如何在 Linux 中检测鼠标和键盘不活动

发布于 2024-08-24 06:24:42 字数 65 浏览 3 评论 0原文

我正在 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

再浓的妆也掩不了殇 2024-08-31 06:24:42

您可以监视 /dev/input/* 文件,当按下某个键/移动鼠标时,它会被写入这些文件之一。

试试这个例子:

fh = file('/dev/input/mice')
while True:                 
    fh.read(3)
    print 'Mouse moved!'

现在我想到了,最好使用 xidle 检测不活动状态。

You could monitor the /dev/input/* files, when a key is pressed/the mouse is moved it is written to one of those files.

Try this for example:

fh = file('/dev/input/mice')
while True:                 
    fh.read(3)
    print 'Mouse moved!'

Now that I think of it, it might be better to use something like xidle to detect inactivity.

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