KeyPress/Release and modifiers

Glynn Clements glynn at gclements.plus.com
Sat Jun 9 09:19:51 PDT 2007


Samuel Thibault wrote:

> > > I have some program that needs to track all pressures/releases of a
> > > given key that I access through modifiers (shift-a for instance), and I
> > > have a problem with the modifier: if I do
> > > 
> > > - press shift
> > > - press a
> > > - release shift
> > > - release a
> > > 
> > > Key events are KeyPress Shift_L, KeyPress 'A', KeyRelease Shift_L,
> > > KeyRelease 'a'.
> > 
> > No, the actual X events are probably:
> > 
> > 	type = KeyPress   keycode = 50
> > 	type = KeyPress   keycode = 38
> > 	type = KeyRelease keycode = 50
> > 	type = KeyRelease keycode = 38
> 
> Ah, yes of course, sorry, I was blindly looking at the result of xev.
> 
> > If you're referring to some higher-level toolkit, try asking in a
> > forum which is specific to that toolkit. Or try to bypass the toolkit.
> 
> It's libX11 and its XLookupString() function :)
> 
> Then maybe what I should just do is on the second event (for which
> XLookupString gives me XK_A), remember the keycode, and when getting the
> fourth event, notice that its the same keycode, and here realize that
> the key was release (i.e. this time not match the keysym, but the
> keycode)?

If you want to match a KeyRelease event to a KeyPress event, compare
keycodes.

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.

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



More information about the xorg mailing list