Re: GdkModifiers bitmask and GDK_SHIFT_MASK question



On Fri, May 19, 2006 at 01:51:07AM +0200, Enrico Tröger wrote:
I have another problem regarding keyboard shortcuts:
in my code I set a bitmask in the following way:

GdkModifier modifiers = GDK_SHIFT_MASK | GDK_CONTROL_MASK;
guint key = GDK_r;

So, this should represent Ctrl+Shift+r.

True, on the other hand it does not represent
Ctrl-Shift-r+NumLock, it does not represent
Ctrl-Shift-r+CapsLock, it does not represent Ctrl-Shift-r
when one ISO-switches to a secondary keyboard, ...

In the callback function for a key-press-event I have the following
code:

gboolean got_key_event(GtkWidget *widget, GdkEventKey *event,
gpointer user_data) 
{
      if (event->keyval == key && event->state == mods)

... therefore a test like this can cause a lot of user
frustration.  See also

http://developer.gnome.org/doc/API/2.0/gtk/gtk-Keyboard-Accelerators.html#gtk-accelerator-get-default-mod-mask

      {
              ...
      }
}
The problem is, for Ctrl+Shift+r this does not work because the
event->keyval is GDK_R.
At the moment I check whether Shift is in event->state and then I
add to the variable key 32 (only if key is between GDK_a and GDK_z) so
the key is the capital of the original value. This works somehow but is
there a better way if the key value is given with GDK_r and not GDK_R?

If the widget is your own, would not be better to use
its GtkBindingSet to map the keystrokes to some signal?
If you cannot do that, well, I simply test explicitly both
GDK_x and GDK_X in such case.

The symbols keys produce are (can be) defined separately for
different states (e.g., 5 types % with Shift).  Letters are
not special in this regard, so Shift-r simply produces
a different symbol: R.  By convention it is an uppercase r,
but you can map it to anything.  To get GDK_r from Shift-r
you would have to map both r and Shift-r to lowercase r in
XKB -- making typing of uppercase letter a bit problematic.
(Well, there is a simplier method: just press CapsLock, you
will get GDK_r with Shift and GDK_R without Shift).

To sum it up, you get all the mods in event->state, but
the symbol you get is already interpreted.

Yeti


--
Anonyms eat their boogers.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]