Linux - Any way to get global KeyPresses without xlib's RECORD? (DBus/HAL/etc?)
I was looking at how to capture global kepresses on Ubuntu Linux regardless of what window has focus. And people suggested some programmes to look at. But they all use the RECORD thing in XLib, which is broken in Ubuntu. Is there some other way to capture all the keypres开发者_StackOverflowses on Ubuntu? How about using HAL? DBus?
You can open the /dev/input/eventN device corresponding to the keyboard(s) and read the keyboard events from there. You'll even get keyboard events from the non-X consoles. This is the "evdev" interface.
From Documentation/input/input.txt in the kernel source:
You can use blocking and nonblocking reads, also
select()on the/dev/input/eventXdevices, and you'll always get a whole number of input events on a read. Their layout is:
struct input_event {
struct timeval time;
unsigned short type;
unsigned short code;
unsigned int value;
};
timeis the timestamp, it returns the time at which the event happened. Type is for exampleEV_RELfor relative moment,REL_KEYfor a keypress or release. More types are defined ininclude/linux/input.h.
codeis event code, for exampleREL_XorKEY_BACKSPACE, again a complete list is ininclude/linux/input.h.
valueis the value the event carries. Either a relative change forEV_REL, absolute new value forEV_ABS(joysticks ...), or 0 forEV_KEYfor release, 1 for keypress and 2 for autorepeat.
加载中,请稍侯......
精彩评论