forked from fogleman/FeedNotifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
idle.py
30 lines (25 loc) · 814 Bytes
/
idle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import sys
if sys.platform == 'win32':
from ctypes import *
class LASTINPUTINFO(Structure):
_fields_ = [
('cbSize', c_uint),
('dwTime', c_int),
]
def get_idle_duration():
lastInputInfo = LASTINPUTINFO()
lastInputInfo.cbSize = sizeof(lastInputInfo)
if windll.user32.GetLastInputInfo(byref(lastInputInfo)):
millis = windll.kernel32.GetTickCount() - lastInputInfo.dwTime
return millis / 1000.0
else:
return 0
else:
def get_idle_duration():
return 0
if __name__ == '__main__':
import time
while True:
duration = get_idle_duration()
print 'User idle for %.2f seconds.' % duration
time.sleep(1)