问题
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.
回答1:
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.
回答2:
look for expectk, it's open source and will provide examples.
回答3:
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
回答4:
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.
来源:https://stackoverflow.com/questions/351185/is-there-a-simple-way-to-detect-mouse-or-keyboard-activity-in-linux-xorg-qt4-kde