如何在Linux中检测鼠标和键盘不活动 [英] How to detect mouse and keyboard inactivity in linux
本文介绍了如何在Linux中检测鼠标和键盘不活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用python开发一个应用程序,该应用程序将检查用户是否处于非活动状态.有没有一种方法可以检查Linux中的按键和鼠标移动事件?
I am developing an app on python which will check for user inactivity. Is there a way to check for key press and mouse move events in linux?
推荐答案
您可以监视/dev/input/*文件,当按下键/移动鼠标时,会将其写入其中一个文件中.
You could monitor the /dev/input/* files, when a key is pressed/the mouse is moved it is written to one of those files.
尝试例如:
fh = file('/dev/input/mice')
while True:
fh.read(3)
print 'Mouse moved!'
现在我想到了,最好使用 xidle 之类的东西来检测不活动状态.
Now that I think of it, it might be better to use something like xidle to detect inactivity.
这篇关于如何在Linux中检测鼠标和键盘不活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文