Synthesizing keyboard events

Daniel Stone daniel at
Mon Dec 11 15:26:40 PST 2006

On Mon, Dec 11, 2006 at 10:18:17PM +0100, Samuel Thibault wrote:
> We would like to synthesize keyboard events.  For instance, synthesize
> typing XK_at.  The problem we encounter is that on a lot of keyboards,
> this is not available directly, but in combination with some modifiers.
> - Calling XKeysymToKeycode(XK_at) is not sufficient, since it doesn't
> give us the modifier mask to synthesize.
> - Looping calling XKeycodeToKeysym() doesn't seem to be very useful: one
> can one know the modifiers for reaching the given index?
> - One possibility would be to call XkbTranslateKeycode() with every
> modifier combination until one is found, but that's a bit slow...
> Is there any direct way to get the keycode and modifier mask to be
> synthesized?

The way apps like Dasher do it, is to take a ring buffer of ten or so
unused keycodes, and remap them at will.  So, if you need to synthesize
at, number, and dollarsign, you take 143, 144, and 145 (e.g.), remap
them, and then send those keycodes.  You cycle through until you hit the
end of your keycode space, and then start again.

Yes, this sucks.  Working on a better solution. :)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <>

More information about the xorg mailing list