根据鼠标和键盘交互检测计算机是否空闲 [英] Detecting if computer is idle based on mouse and keyboard interactions

查看:366
本文介绍了根据鼠标和键盘交互检测计算机是否空闲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C ++中编写一个软件控制我的MacBook Pro的键盘背光,运行Arch Linux作为主操作系统和Debian的funzies。该程序作为守护程序运行,并且现在能够打开键盘背光。下一步是让它保持注意当计算机空闲(基于鼠标和键盘的交互),当它已经空闲了一段时间,关闭背光,一旦与键盘或鼠标的交互注册,再次打开背光。



我已经搜索了,但我没有找到任何我可以工作来检查最后一次鼠标和/或键盘的互动。 / p>

任何想法如何实现这一点?
我相信在任何Linux操作系统(也许X?)的某些部分已经存在这样的功能,所以使用这将是更好的,而不是从头开始写。



X服务器中的XScreensaver扩展跟踪键盘和鼠标的空闲时间。如果您将源代码下载到 Psi ,则其源代码树会有一个文件 idle_x11.cpp ,它包含查询空闲时间的逻辑。以此为例。



基本思想是使用 XScreenSaverQueryInfo 来读取屏幕保护程序状态信息。 / p>

I'm am writing a piece of software in C++ that controls the keyboard backlight on my MacBook Pro which runs Arch Linux as main OS and Debian for funzies. The program runs as a daemon and is as of now able to turn the keyboard backlight on. Next step is to make it keep an eye on when the computer is idle (based on mouse and keyboard interactions) and when it has been idle for some time, turn off the backlight, and as soon an interaction with keyboard or mouse is registered, turn the backlight on again.

I have googled around, but I havent found anything I could get working to check when the last mouse and/or keyboard interaction was registered.

Any idea to how I can achieve this? I believe there already exists such capabilities in some part of any Linux OS (maybe X?) so using this would be preferable instead of writing from scratch.

Regards,...

解决方案

The XScreensaver extension in the X server tracks keyboard and mouse idle time. If you download the source code to Psi, their source tree has a file idle_x11.cpp that contains logic to query the idle time. Use that as an example.

The basic idea is to use XScreenSaverQueryInfo to read the screen saver status info.

这篇关于根据鼠标和键盘交互检测计算机是否空闲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆