I’m trying to write a little app to capture keystrokes for a window under X and then display them onto the screen using OSD or something. The idea is to use it for screencasts and stuff like that.
I tried some surgery on xev and got it to work fine but then noticed something funny. If I use xev on the window which itself creates, the KEyPress and KeyRelease events are registered and I can see them. However, if I use the -id switch for xev to monitor another window and try to log keystrokes there, they KeyPress and KeyRelease events are not always displayed. I seem to get PropertyNotify events when some things happen but not KeyPress and KeyRelease which are what I’m interested in.
Some windows behave as expected (e.g. gnome-terminal). Some others don’t (e.g. emacs-gtk).
How do I get the keystrokes for these windows?
Key events go to the window that has focus, which is not always the window that appears to have focus. When I try to use
xevon my firefox window, key events go to one of its unviewable children (relative upper-left at (-1,-1), size (1,1).You can use
XGetInputFocus()to find out which window has focus.