【问题标题】:How to detect mouse and keyboard inactivity in linux如何在linux中检测鼠标和键盘的不活动
【发布时间】:2011-01-24 10:13:15
【问题描述】:

我正在 python 上开发一个应用程序,它将检查用户的不活动状态。有没有办法在linux中检查按键和鼠标移动事件?

【问题讨论】:

    标签: python linux input keyboard mouse


    【解决方案1】:

    您可以监控 /dev/input/* 文件,当按下键/移动鼠标时,它会写入其中一个文件。

    试试这个例子:

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

    现在我想起来了,使用xidle 之类的东西来检测不活动可能会更好。

    【讨论】:

    • 在 Ubuntu Linux 中,使用 xautolock 代替
    • @ВасинЮрий 有几种解决方案,有些不需要 root 权限,但我不确定它们是否可以在 Python 中轻松实现:stackoverflow.com/questions/222606/…
    • @Wolph,我找不到任何工作,甚至 CLI(bash、shell)解决方案。
    • 您尝试过xprintidle 应用程序吗?它可能对你有用。
    猜你喜欢
    • 2010-09-18
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    • 2011-06-09
    • 2011-04-26
    • 2010-09-25
    • 2010-11-23
    • 2016-09-16
    相关资源
    最近更新 更多