-
If there's some better place where xlib experts hang out, please tell me. Despite an assiduous search, I could not find an xlib reflector.
-
My actual question:
In an xterm, I want to grab and process all keyboard events in a program running inside the xterm. For example, with my program running, if I press an "x", I don't the x to be displayed, and I do want to be able to see the keypress and keyrelease events myself, in the application running inside the xterm.
I have tried quite a few things, but nothing seems to do exactly what I need.
The closest I've come is the pseudo-code sequence:
XOpenDisplay() to get the correct display
getenv("WINDOWID") to get the window ID
XGrabKeyboard( <display*>, <window>, false, GrabModeAsync, GrabModeSync, CurrentTime)
XSelectInput(<everything>)
forever: (XWindowEvent() on the window)
But that seems to have two problems:
- it seems to grab keyboard events wherever they occur on the display, not just in the xterm;
- keyboard events inside the xterm don't actually seem to be returned by the XWindowEvent().
This is the first time I've tried to use xlib, so it's perfectly possible (even likely) that I'm missing something basic, even though I've tried to read the pertinent documentation quite carefully.
---------- Post updated at 05:10 PM ---------- Previous update was at 04:57 PM ----------
Apparently, the call to XGrabKeyboard should be:
XGrabKeyboard(<display>, <window>, false, GrabModeAsync, GrabModeAsync, CurrentTime);
although I don't undrestand why the keyboard mode should be Async. The documentation seems to indicate that this would mean that the xterm application would also receive the keyboard activity, but that isn't what happens.
(Documentation says: If the keyboard_mode argument is GrabModeAsync, keyboard event processing continues as usual. Apparently, whatever "as usual" means, it does not seem to mean "is sent to other clients as usual".)
So I'm floundering as to <i>why</i> this works, but at least it does seem to do what I need.