Reputation: 7334
I'd like to send a synthetic keypress event to X. This all seems to work fine for most keys using XSendEvent
to send a KeyPress
event. Unfortunately I can't get it to work for a key that isn't actually on my keyboard - in this case the sterling sign £ (I have a US keyboard).
The problem seems to be that the XKeyEvent
structure needs a keycode
and I only have a KeySym
for this sign. XKeysymToKeycode
returns 0 because there isn't a key for it.
Does anyone know how I can achieve this? It may be that I need some rather different approach here - any advice is appreciated!
Upvotes: 1
Views: 2316
Reputation: 1460
@Peter you're looking along the right lines. Part of the challenge is that the set of KeySyms
is much larger than the size of keycode
. You can resolve this by modifying the keymap just before synthesising the event.
Take a look at libfakekey
: http://git.yoctoproject.org/cgit/cgit.cgi/libfakekey/tree/src/libfakekey.c
And in particular: fakekey_press_keysym
function which takes a KeySym
to send rather than just a code.
Upvotes: 2