开发者

How to detect mouse and keyboard inactivity in linux

开发者 https://www.devze.com 2022-12-21 22:42 出处:网络
I am developing an app on 开发者_JAVA技巧python which will check for user inactivity. Is there a way to check for key press and mouse move events in linux?You could monitor the /dev/input/* files, whe

I am developing an app on 开发者_JAVA技巧python which will check for user inactivity. Is there a way to check for key press and mouse move events in linux?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消