Sign up

Pages: 1 2

Using modifers to make things happen

Eg. Control + S to save (or what ever)

I've got a program with a notes part of it and I want to be able to just hit Control + S to save, instead of using the mouse each time.

Thanks.

Re: Using modifers to make things happen

On Thu, 27 Jun 2013 02:50:02 GMT, Joel wrote:

Eg. Control + S to save (or what ever)

I've got a program with a notes part of it and I want to be able to just hit Control + S to save, instead of using the mouse each time.

Thanks.

To setup keyboard shortcuts you'll need to create an accelGroup and add it to the window.

AccelGroup accelGroup = new AccelGroup();
window.addAccelGroup(accelGroup);

And when creating the MenuItems you can pass in the accelGroup and set the accelKey:

new MenuItem(&onSave, "_Save", "file.save", true, accelGroup, 's');

Now onSave will be called when the menu item is clicked and when the Window receives Crtl+S.

Re: Using modifers to make things happen

new MenuItem(&onSave, "_Save", "file.save", true, accelGroup, 's');

Now onSave will be called when the menu item is clicked and when the Window receives Crtl+S.

Where is 'Ctrl' at?

Is "_Save" for using Alt + S?

P.S. I'd be faster at replying if I got notified by e-mail, I think. I forget about these posts.

Re: Using modifers to make things happen

On 06/30/2013 01:47 AM, Joel wrote:

Where is 'Ctrl' at?

Usually on the left and right side of the keyboard?

Is "_Save" for using Alt + S?

Yes, it's for browsing/accessing the menu using Alt.

P.S. I'd be faster at replying if I got notified by e-mail, I think. I forget about these posts.

Re: Using modifers to make things happen

On Sun, 30 Jun 2013 16:17:00 +0200, Mike Wey wrote:

On 06/30/2013 01:47 AM, Joel wrote:

Where is 'Ctrl' at?

Usually on the left and right side of the keyboard?

Your code example doesn't seem to use Ctrl. That is what I mean.

Re: Using modifers to make things happen

On 07/01/2013 08:57 AM, Joel wrote:

On Sun, 30 Jun 2013 16:17:00 +0200, Mike Wey wrote:

On 06/30/2013 01:47 AM, Joel wrote:

Where is 'Ctrl' at?

Usually on the left and right side of the keyboard?

Your code example doesn't seem to use Ctrl. That is what I mean.

It's one of the default parameters, specifying all parameters you'll get:

new MenuItem(&onSave, "_Save", "file.save", true, accelGroup, 's', 
GdkModifierType.CONTROL_MASK, GtkAccelFlags.VISIBLE);

Re: Using modifers to make things happen

Thanks for your replies, Mike. I'll try to get it working, some time soon, hopefully.

Re: Using modifers to make things happen

Yay, it works. I can just hit control + S save my work, and not have to move the mouse at all. Though I used a dummy menu item, that was attached to the grid, but not shown. Is there a better way?

Thanks Mike.

P.S. I can't login here, it says I don't have a right username

Re: Using modifers to make things happen

On Wed, 07 Aug 2013 01:08:13 GMT, Joel Christensen wrote:

Yay, it works. I can just hit control + S save my work, and not have to move the mouse at all. Though I used a dummy menu item, that was attached to the grid, but not shown. Is there a better way?

As far as i know the AccelGroup need to be associated with an menuItem to function properly.

Thanks Mike.

P.S. I can't login here, it says I don't have a right username

It looks like you didn't sign up / register, at least not with the e-mail address your currently using.

Re: Using modifers to make things happen

On Wed, 07 Aug 2013 20:58:52 GMT, Mike Wey wrote:

On Wed, 07 Aug 2013 01:08:13 GMT, Joel Christensen wrote:

Yay, it works. I can just hit control + S save my work, and not have to move the mouse at all. Though I used a dummy menu item, that was attached to the grid, but not shown. Is there a better way?

As far as i know the AccelGroup need to be associated with an menuItem to function properly.

This might also work: (i wasn't able to test it)

window.addOnKeyPress(&keyPressCallback);

bool keyPressCallback(Event ev, Widget w)
{
	if ( ev.key.keyval == GdkKeysyms.GDK_s
		&& ev.key.state == GdkModifierType.CONTROL_MASK )
	{
		//Do stuff.

		return true;
	}

	return false;
}

Pages: 1 2