PDA

View Full Version : Grabbing X input - help


Guest
November 17th, 2006, 05:37 PM
What i would like to do is get all the keys which are being pressed at a certain time (including modifiers). Does anyone know which X function i should be looking at? Or even better an example.

RYX
November 17th, 2006, 06:09 PM
I don't know any X-function for that, but if you have gdk/gtk you can use gdk_window_add_filter() to add a callback on any window (but you don't want to use gtk/gdk, right?) ... you could look into the gdk/gtk source and check what gdk_window_add_filter() does - it maybe uses the X-functions you need.

Edit: Maybe XSelectInput (http://tronche.com/gui/x/xlib/event-handling/XSelectInput.html)? You can use NULL as window to handle all event sent to the root window ...

:)

mikedee
November 17th, 2006, 06:40 PM
I think the X function is XGrabKeyboard

http://tronche.com/gui/x/xlib/input/XGrabKeyboard.html

Once you have the grab, I think you need to monitor for KeyPress events, modifiers and normal keys are all treated the same by X so you shouldnt have a problem. The key format used by compiz in the configuration is the keysym.

http://tronche.com/gui/x/xlib/events/keyboard-pointer/keyboard-pointer.html#XKeyEvent

There is an example in compiz in the screen.c file in the pushScreenGrab function. There is also a program called xev which is very useful when working with events, the source code to it is a mini example. There are lots of other x programs like this too which can be good real world reference.