Is there a simple way to detect mouse or keyboard activity in Linux or Xorg or Qt4 or Kde4 environment? Obviously not only on a particular window but in the entire Xorg desktop.
Thanks for the help.
Is there a simple way to detect mouse or keyboard activity in Linux or Xorg or Qt4 or Kde4 environment? Obviously not only on a particular window but in the entire Xorg desktop.
Thanks for the help.
I'm not familiar with the guts of the Qt4 or KDE API's.
However in general terms, on any X11 system keyboard or mouse input is only delivered to the active window, unless you call the underlying XGrabMouse
, XGrabKeyboard
, etc functions.
Of course, once you've done that, no other window can receive those input events, so you have to make very sure that there's a way for your program to release the mouse and/or keyboard input once you're done.
You can use the XScreenSaver extension (man Xss
). It can provide you with values into this struct using the function XScreenSaverQueryInfo
:
typedef struct {
Window window; /∗ screen saver window */
int state; /∗ ScreenSaver{Off,On,Disabled} */
int kind; /∗ ScreenSaver{Blanked,Internal,External} */
unsigned long til_or_since; /∗ milliseconds */
unsigned long idle; /∗ milliseconds */
unsigned long event_mask; /∗ events */
} XScreenSaverInfo;
The idle field specifies the number of milliseconds since the last input was received from the user on any of the input devices.
I don't know about a Qt only solution for this.
Try XRecord (grabing key&mouse is another common solution but it has issues with other applications grabbing).
Here is some link I used some time ago: http://mtoader.blogspot.com/2005/02/you-want-recording-x11-event-recording.html