forked from fogleman/FeedNotifier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidle.py
More file actions
79 lines (55 loc) · 1.63 KB
/
idle.py
File metadata and controls
79 lines (55 loc) · 1.63 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -*- coding: utf-8 -*-
"""[summary]
Returns:
[type] -- [description]
"""
import logging
import sys
import time
if sys.platform.startswith('win32'):
from ctypes import *
if sys.platform.startswith('win32'):
# Detecting idle time using python
# https://stackoverflow.com/questions/911856/detecting-idle-time-using-python
#
# https://stackoverflow.com/questions/217157/how-can-i-determine-the-display-idle-time-from-python-in-windows-linux-and-mac?noredirect=1&lq=1
# TODO:
class LASTINPUTINFO(Structure):
"""[summary]
Arguments:
Structure {[type]} -- [description]
"""
_fields_ = [
('cbSize', c_uint),
('dwTime', c_int),
]
def get_idle_duration():
"""[summary]
Returns:
[type] -- [description]
"""
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
elif sys.platform.startswith('darwin'):
print('We are in MacOX') # FIXME: ¿?
def get_idle_duration():
return 0
elif sys.platform.startswith('linux'):
print('We are in linux') # FIXME: ¿?
def get_idle_duration():
return 0
else:
pass
# def get_idle_duration():
# return 0
if __name__ == '__main__':
while True:
duration = get_idle_duration()
logging.debug(('User idle for %.2f seconds.' % duration))
time.sleep(1)
# EOF