From b3115437ddf7aadeb7f637cd73a7753953608c6b Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Mon, 16 Feb 2004 19:00:16 +0000 Subject: [PATCH] Added an example of how to use GDK_MODIFIER_MASK to test for modifier keys 2004-02-16 Federico Mena Quintero * gdk/tmpl/windows.sgml: Added an example of how to use GDK_MODIFIER_MASK to test for modifier keys correctly. * gtk/migrating-checklist.sgml: Likewise. --- docs/reference/ChangeLog | 2 + docs/reference/gtk/migrating-checklist.sgml | 48 +++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 9478a875ee..a049d527a9 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -3,6 +3,8 @@ * gdk/tmpl/windows.sgml: Added an example of how to use GDK_MODIFIER_MASK to test for modifier keys correctly. + * gtk/migrating-checklist.sgml: Likewise. + Sun Feb 15 23:51:08 2004 Matthias Clasen * gtk/tmpl/gtkcomboboxentry.sgml: diff --git a/docs/reference/gtk/migrating-checklist.sgml b/docs/reference/gtk/migrating-checklist.sgml index 08eba65c8b..9c83a7030a 100644 --- a/docs/reference/gtk/migrating-checklist.sgml +++ b/docs/reference/gtk/migrating-checklist.sgml @@ -210,6 +210,54 @@ my_widget_expose_event_handler (GtkWidget *widget, GdkEventExpose *event) } + +
+ Test for modifier keys correctly + + + Why + + With GDK_MODIFIER_MASK you can test for + modifier keys reliably; this way your key event handlers will + work correctly even if NumLock or + CapsLock are activated. + + + + + In a GdkEventKey, the + state field is a bit mask which + indicates the modifier state at the time the key was pressed. + Modifiers are keys like Control, and + NumLock. When implementing a GtkWidget::key_press_event + handler, you should use the + GDK_MODIFIER_MASK constant to test against + modifier keys. This value encompasses all the modifiers which + the user may be actively pressing, such as + Control and Shift, but ignores + "inocuous" modifiers such as NumLock and + CapsLock. The following example tests for + + ControlF10 being + pressed. + + + +static gboolean +my_widget_key_press_handler (GtkWidget *widget, GdkEventKey *event) +{ + if (event->keysym == GDK_F10 + && (event->state & GDK_MODIFIER_MASK) == GDK_CONTROL_MASK) + { + g_print ("Control-F10 was pressed\n"); + return TRUE; + } + + return FALSE; +} + +