Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect mouse and keyboard inactivity in 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?

like image 351
user287658 Avatar asked Mar 06 '10 09:03

user287658


1 Answers

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.

like image 104
Wolph Avatar answered Oct 05 '22 13:10

Wolph