6

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?

user287658
  • 63
  • 1
  • 3

1 Answers1

6

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.

Wolph
  • 74,301
  • 10
  • 131
  • 146
  • 1
    In Ubuntu Linux, `xautolock` is used instead – kolypto Nov 16 '10 at 08:58
  • @ВасинЮрий There are several solutions, some don't require root rights but I'm not sure if they can be implemented in Python easily: http://stackoverflow.com/questions/222606/detecting-keyboard-mouse-activity-in-linux – Wolph Feb 11 '17 at 13:49
  • @Wolph, I can't find any working, even CLI (bash, shell) solution. – Vasin Yuriy Feb 12 '17 at 17:59
  • 1
    Have you tried the `xprintidle` app? It might work for you. – Wolph Feb 12 '17 at 22:57