有没有一种简单的方法来检测 Linux/Xorg/Qt4/Kde4 中的鼠标或键盘活动?

发布于 2024-07-10 03:45:21 字数 88 浏览 13 评论 0原文

有没有一种简单的方法可以检测 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

只有一腔孤勇 2024-07-17 03:45:21

您可以使用 XScreenSaver 扩展 (man Xss)。 它可以使用函数 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;

空闲字段指定自上次在任何输入设备上从用户接收到输入以来的毫秒数。

我不知道 Qt 对此有唯一的解决方案。

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.

过去的过去 2024-07-17 03:45:21

寻找expectk,它是开源的并且会提供示例。

look for expectk, it's open source and will provide examples.

挽袖吟 2024-07-17 03:45:21

尝试 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

丢了幸福的猪 2024-07-17 03:45:21

我不熟悉 Qt4 或 KDE API 的内部结构。

但一般而言,在任何 X11 系统上,键盘或鼠标输入仅传递到活动窗口,除非您调用底层 XGrabMouseXGrabKeyboard等功能。

当然,一旦完成,其他窗口就无法接收这些输入事件,因此您必须确保程序有一种方法可以在完成后释放鼠标和/或键盘输入。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文