[Gambas-devel] [Gambas-user] Highlight Editor - Capslock Key State

Benoit Minisini gambas at ...1...
Wed Feb 13 22:49:17 CET 2008


On mercredi 13 février 2008, Rob wrote:
> On Wednesday 13 February 2008 15:08, Benoit Minisini wrote:
> > Interesting problem. I don't know if there is a way to know the
> > status of CAPS LOCK, or other modifier keys.
>
> I think there is.  At the end of this post is the output of xev when I
> press "a" three times, turning caps lock on and off in between.
> Looking at the source of xev, the current status of the caps lock key
> seems to be bit 1 (value of 2) in XKeyEvent->state, which seems to
> correspond to the macro LockMask in X.h:
>
> /* from xev.c */
> const char *Yes = "YES";
> const char *No = "NO";
> /* ... */
> static void do_KeyPress (XEvent *eventp)
> {
>     XKeyEvent *e = (XKeyEvent *) eventp;
>     KeySym ks;
>     char *ksname;
>     /* ... */
>     printf ("    state 0x%x, keycode %u (keysym 0x%lx, %s),
>                  same_screen %s,\n",
>             e->state, e->keycode, (unsigned long) ks, ksname,
>             e->same_screen ? Yes : No);
> }
> /* the above outputs "state 0x2" when caps lock is on */
>
> /* from X.h */
> #define LockMask                (1<<1) /* i.e., 0x2 */
>
> So someone using gb.api could probably detect the caps lock key the
> first time a key is pressed, after a little bit of painful libX11
> manipulation.  While this would only work when the user presses a
> key, the state flag is also passed with XMotionEvent, and appears to
> work the same way, so whenever the user moved the mouse you'd have
> your caps lock state as well.
>
> This doesn't seem to work for Scroll Lock, and I don't have a Num Lock
> key on my laptop so I don't know whether that would work too.
>
> Rob
>
> KeyPress event, serial 31, synthetic NO, window 0x3c00001,
>     root 0x5d, subw 0x0, time 1286280441, (486,459), root:(489,543),
>     state 0x0, keycode 38 (keysym 0x61, a), same_screen YES,
>     XLookupString gives 1 bytes: (61) "a"
>     XmbLookupString gives 1 bytes: (61) "a"
>     XFilterEvent returns: False
>
> KeyRelease event, serial 31, synthetic NO, window 0x3c00001,
>     root 0x5d, subw 0x0, time 1286280497, (486,459), root:(489,543),
>     state 0x0, keycode 38 (keysym 0x61, a), same_screen YES,
>     XLookupString gives 1 bytes: (61) "a"
>     XFilterEvent returns: False
>
> KeyPress event, serial 31, synthetic NO, window 0x3c00001,
>     root 0x5d, subw 0x0, time 1286281927, (486,459), root:(489,543),
>     state 0x0, keycode 66 (keysym 0xffe5, Caps_Lock), same_screen YES,
>     XLookupString gives 0 bytes:
>     XmbLookupString gives 0 bytes:
>     XFilterEvent returns: False
>
> KeyRelease event, serial 31, synthetic NO, window 0x3c00001,
>     root 0x5d, subw 0x0, time 1286282007, (486,459), root:(489,543),
>     state 0x2, keycode 66 (keysym 0xffe5, Caps_Lock), same_screen YES,
>     XLookupString gives 0 bytes:
>     XFilterEvent returns: False
>
> KeyPress event, serial 31, synthetic NO, window 0x3c00001,
>     root 0x5d, subw 0x0, time 1286282869, (486,459), root:(489,543),
>     state 0x2, keycode 38 (keysym 0x41, A), same_screen YES,
>     XLookupString gives 1 bytes: (41) "A"
>     XmbLookupString gives 1 bytes: (41) "A"
>     XFilterEvent returns: False
>
> KeyRelease event, serial 31, synthetic NO, window 0x3c00001,
>     root 0x5d, subw 0x0, time 1286282933, (486,459), root:(489,543),
>     state 0x2, keycode 38 (keysym 0x41, A), same_screen YES,
>     XLookupString gives 1 bytes: (41) "A"
>     XFilterEvent returns: False
>
> KeyPress event, serial 31, synthetic NO, window 0x3c00001,
>     root 0x5d, subw 0x0, time 1286283508, (486,459), root:(489,543),
>     state 0x2, keycode 66 (keysym 0xffe5, Caps_Lock), same_screen YES,
>     XLookupString gives 0 bytes:
>     XmbLookupString gives 0 bytes:
>     XFilterEvent returns: False
>
> KeyRelease event, serial 31, synthetic NO, window 0x3c00001,
>     root 0x5d, subw 0x0, time 1286283587, (486,459), root:(489,543),
>     state 0x2, keycode 66 (keysym 0xffe5, Caps_Lock), same_screen YES,
>     XLookupString gives 0 bytes:
>     XFilterEvent returns: False
>
> KeyPress event, serial 31, synthetic NO, window 0x3c00001,
>     root 0x5d, subw 0x0, time 1286284033, (486,459), root:(489,543),
>     state 0x0, keycode 38 (keysym 0x61, a), same_screen YES,
>     XLookupString gives 1 bytes: (61) "a"
>     XmbLookupString gives 1 bytes: (61) "a"
>     XFilterEvent returns: False
>
> KeyRelease event, serial 31, synthetic NO, window 0x3c00001,
>     root 0x5d, subw 0x0, time 1286284097, (486,459), root:(489,543),
>     state 0x0, keycode 38 (keysym 0x61, a), same_screen YES,
>     XLookupString gives 1 bytes: (61) "a"
>     XFilterEvent returns: False
>

There is better apaprently: XkbGetIndicatorState() and XkbGetNamedIndicator().

-- 
Benoit Minisini




More information about the Devel mailing list