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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.