|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Key handling problemsHi all,
I'm trying to check if a user press some keys. I want to check If the user press control+j. I'm having problems with it. I paste my code: guint key = self->priv->key; if ((event->state & self->priv->mod) == self->priv->mod && event->keyval == key) { xxxxxxxxx } Currently this code do: 1.- If the user has NumLk enabled works fine 2.- If the user has lock caps enable it doesn't work because the j is not j is J (upper) 3.- The control check works fine 4.- If I press contro+alt+j works (It may fail because I want to check control+j not control+alt+j) 5.- If I press contro+shift+j doesn't work because the j is not J but the state check sais true I have tried 1000 ways to do it, I have see a lot of code but I have not luck Can you help me? I'm desperated :( Regards, Perriman _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@... http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list |
|
|
Re: Key handling problemsOn Thu, 18 Sep 2008, Perriman wrote:
> I'm trying to check if a user press some keys. I want to check > If the user press control+j. I'm having problems with it. I paste my > code: > > guint key = self->priv->key; > > if ((event->state & self->priv->mod) == self->priv->mod && > event->keyval == key) > { > xxxxxxxxx > } > > Currently this code do: > > 1.- If the user has NumLk enabled works fine > 2.- If the user has lock caps enable it doesn't work because the j is > not j is J (upper) > 3.- The control check works fine > 4.- If I press contro+alt+j works (It may fail because I want to > check control+j not control+alt+j) > 5.- If I press contro+shift+j doesn't work because the j is not J but > the state check sais true > > I have tried 1000 ways to do it, I have see a lot of code but I have > not luck > > Can you help me? I'm desperated :( If you're attaching to the "key_press_event" on some widget, you can do something like this in your callback: gboolean catch_ctrl_j (GtkWidget *w, GdkEventKey *key, gpointer p) { GdkModifierType mods; gdk_window_get_pointer(w->window, NULL, NULL, &mods); /* make the j/J case insensitive? */ if (gdk_keyval_to_upper(key->keyval) == GDK_J) { if (mods & GDK_CONTROL_MASK) { printf("Got ctrl-j"); if (mods & GDK_MOD1_MASK) { printf("Got ctrl-alt-j"); } } } return FALSE; } If you'e handling the keystroke and don't want the default handler invoked, then return TRUE instead. -- Allin Cottrell Department of Economics Wake Forest University, NC _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@... http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list |
|
|
Re: Key handling problemsThank you very much
I have a question: Why I check GDK_MOD1_MASK and not another mask? I want the control+j but not the lock caps+control+j neither num lock+control+j etc. Regards, Perriman El Wed, 17 Sep 2008 21:50:08 -0400 (EDT) Allin Cottrell <cottrell@...> escribió: > On Thu, 18 Sep 2008, Perriman wrote: > > > I'm trying to check if a user press some keys. I want to > > check If the user press control+j. I'm having problems with it. I > > paste my code: > > > > guint key = self->priv->key; > > > > if ((event->state & self->priv->mod) == self->priv->mod && > > event->keyval == key) > > { > > xxxxxxxxx > > } > > > > Currently this code do: > > > > 1.- If the user has NumLk enabled works fine > > 2.- If the user has lock caps enable it doesn't work because the j > > is not j is J (upper) > > 3.- The control check works fine > > 4.- If I press contro+alt+j works (It may fail because I want to > > check control+j not control+alt+j) > > 5.- If I press contro+shift+j doesn't work because the j is not J > > but the state check sais true > > > > I have tried 1000 ways to do it, I have see a lot of code but I have > > not luck > > > > Can you help me? I'm desperated :( > > If you're attaching to the "key_press_event" on some widget, you > can do something like this in your callback: > > gboolean > catch_ctrl_j (GtkWidget *w, GdkEventKey *key, gpointer p) > { > GdkModifierType mods; > > gdk_window_get_pointer(w->window, NULL, NULL, &mods); > > /* make the j/J case insensitive? */ > if (gdk_keyval_to_upper(key->keyval) == GDK_J) { > if (mods & GDK_CONTROL_MASK) { > printf("Got ctrl-j"); > if (mods & GDK_MOD1_MASK) { > printf("Got ctrl-alt-j"); > } > } > } > > return FALSE; > } > > If you'e handling the keystroke and don't want the default handler > invoked, then return TRUE instead. > > -- > Allin Cottrell > Department of Economics > Wake Forest University, NC gtk-app-devel-list mailing list gtk-app-devel-list@... http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list |
|
|
Re: Key handling problemsOn Fri, 19 Sep 2008, Perriman wrote:
> Thank you very much > > I have a question: > Why I check GDK_MOD1_MASK and not another mask? > > I want the control+j but not the lock caps+control+j neither > num lock+control+j etc. GDK_MOD1_MASK (usually) gives you the alt key, in case you want to screen that out (I thought you said something to that effect). As for the rest, check out the Gdk documentation, e.g. http://library.gnome.org/devel/gdk/stable/gdk-Windows.html Allin Cottrell _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@... http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list |
| Free Forum Powered by Nabble | Forum Help |