KeyPress/Release and modifiers

Glynn Clements glynn at gclements.plus.com
Sun Jun 10 05:56:22 PDT 2007


Samuel Thibault wrote:

> > If you're interested in KeyRelease events, then you're probably
> > viewing the keyboard as a collection of "push buttons". In that case,
> > keycodes are a more appropriate identifier. A KeySym is a higher-level
> > abstraction, which may result from multiple KeyPress events (due to
> > dead keys, compose processing, etc). If you're working in terms of
> > KeySyms, KeyRelease events aren't really meaningful.
> 
> What I'm implementing is a braille keyboard on a standard PC keyboard.
> 
> Thus, since it means pressing chords of keys, I'm interested in
> KeyRelease events. However, I'd prefer letting the user choose which
> keys should produce braille simply via the keycode/keysym conversion
> (and on the long run provide an xkb option for this).

In that case, I suggest translating the user-specified KeySyms to
KeyCodes, storing the KeyCodes, and matching KeyPress/KeyRelease
events to those KeyCodes.

To perform the translation, I would suggest searching the mapping
table returned by XGetKeyboardMapping(); unmodified keys should be
preferred over modified keys.

You could use XKeysymToKeycode(), but I don't know how that will
handle the case where a KeySym is available on multiple keys. E.g. on
a UK keyboard, XK_bracketright can be generated by key 35 (the "]"+"}"
key) with no modifiers, or by key 18 (the "9"+"(" key) with AltGr. If
the user chooses XK_bracketright, you probably want the former rather
than the latter or both.

If you provide an interactive configuration option, where the user
chooses the keys by pressing them, record the keycode directly.

-- 
Glynn Clements <glynn at gclements.plus.com>





More information about the xorg mailing list