Hm. Put this in ~/bin/test.py
PHP Code:
#!/usr/bin/env python
from subprocess import Popen,PIPE,STDOUT,call
import os
import time
def get_idle_time():
proc=Popen('xidle', shell=True, stdout=PIPE, )
return float(proc.communicate()[0])
sleep_seconds=1
max_idle=5
last_idle=0
while True:
idle=get_idle_time()
print(idle)
if ((last_idle<max_idle and max_idle<=idle) or
(idle<max_idle and max_idle<=last_idle)):
print('Shift+F9')
last_idle=idle
time.sleep(sleep_seconds)
Make it executable:
Code:
chmod +x ~/bin/test.py
And the run it:
Wait for >5 seconds, then move the mouse.
Do you see output like this:
Code:
% test.py
0.047
1.002
2.006
3.01
4.013
5.014
Shift+F9 <---- First Shift+F9 happens after 5 seconds
6.018
7.022
0.682
Shift+F9 <---- Mouse movement causes a Shift+F9
1.686
2.69
^CTraceback (most recent call last):
File "/home/cyrano/pybin/idlerain.py", line 21, in <module>
time.sleep(sleep_seconds)
KeyboardInterrupt
Note this program does not issue any real Shift+F9, it's just to see if the
mechanics of the program are working.
Bookmarks