Gtk keypress modifiers
I try to check if control key is pressed but I can't. According to documentation I try this:
G_MODULE_EXPORT gboolean
KEYPRESS_window1(GtkWidget *window1, GdkEventKey* pKey, gpointer user_data)
{
guint modifiers;
modifiers = gtk_accelerator_get_default_mod_mask();
g_print("modifiers %d\n", modifiers);
g_print("pKey->state %d\n", pKey->state);
if ((pKey->state & modifiers) == GDK_CONTROL_MASK)
{
ctrlp开发者_开发百科ressed = 1;
return TRUE;
}
return FALSE;
}
Signals are raised and passes correctly but logic dont passes "if" condition. I would like to know why, so please help.
To check whether Ctrl is just pressed by itself, you need to examine the key code of the pressed key. You should be able to examine the keyval
field of the event and check for GDK_KEY_Control_L
or GDK_KEY_Control_R
. You could also check the hardware_keycode
field, but I don't know if that's portable.
精彩评论