How to intercept all keyboard events

Daniel dan.in.a.bottle at gmail.com
Fri Sep 24 12:08:31 PDT 2010


Hi all,

I would like to have permanent exclusive access to keyboard events and
the possibility to drop arriving events and create new ones before
they are finally delivered to the application over the normal X
channels (window with keyboard focus, grabs).

The first attempt to get this working was with passive grabs on all
keys from within a WM. Unfortunately, passive grabs don't behave
consistently when overlapping key events occur: keyPress A, keyPress
B, keyRelease A, keyRelease B with passive grabs on A and B looses the
last keyRelease B, because the converted passive grab is ended on
keyRelease A (A and B are unmodified keys). This was implemented using
Xlib.

I haven't attempted to use an active grab yet, mainly because I've got
the impression that active grabs should only be used for short periods
of time. Is this correct? I worry a bit about having an active grab on
the root window from inside a WM or similar for the duration of an
entire session.

I think XEvIE would have solved my exact problem, but that extension
died due to lack of a maintainer (and I can't find documentation
anymore, all links on the wiki are broken). I also looked at XInput2,
but it didn't strike me that it would be better suited for my problem
than Xlib itself.

So what do people do in similar situations? I think that input
methods, and accessibility related projects need to solve a similar
problem. Although I feel that both problem areas are a lot more
complex than mine, as they need to provide UI interaction, which I
don't.

If necessary, I'm willing to dig deeper into either X, Linux
kernel/driver code, or any other technology to solve this problem, but
right now I'm lacking the knowledge and experience to find out which
way is the most promising.

Any pointers very welcome.

Thanks,
Daniel

PS: I have a similar question open on stackoverflow:
http://stackoverflow.com/questions/3781831 (answers are welcome both
here and there, whatever suits you. I will update the question on SO
if necessary, once I know what the answer is).
PPS: the final result is going to be similar to keyboa:
http://github.com/meingbg/keyboa (works only over VNC)



More information about the xorg mailing list