有没有一种简单的方法来检测 Linux/Xorg/Qt4/Kde4 中的鼠标或键盘活动?
有没有一种简单的方法可以检测 Linux 或 Xorg 或 Qt4 或 Kde4 环境中的鼠标或键盘活动? 显然不仅在特定窗口上,而且在整个 Xorg 桌面上。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 XScreenSaver 扩展 (
man Xss
)。 它可以使用函数XScreenSaverQueryInfo
为您提供此结构中的值:我不知道 Qt 对此有唯一的解决方案。
You can use the XScreenSaver extension (
man Xss
). It can provide you with values into this struct using the functionXScreenSaverQueryInfo
:I don't know about a Qt only solution for this.
寻找expectk,它是开源的并且会提供示例。
look for expectk, it's open source and will provide examples.
尝试 XRecord(抓取键和鼠标是另一种常见的解决方案,但它与其他应用程序抓取存在问题)。
这是我前段时间使用的一些链接: http://mtoader.blogspot.com/2005/02/you-want-recording-x11-event-recording.html
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
我不熟悉 Qt4 或 KDE API 的内部结构。
但一般而言,在任何 X11 系统上,键盘或鼠标输入仅传递到活动窗口,除非您调用底层
XGrabMouse
、XGrabKeyboard
等功能。当然,一旦完成,其他窗口就无法接收这些输入事件,因此您必须确保程序有一种方法可以在完成后释放鼠标和/或键盘输入。
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.