The following Python code is supposed to print out how much time has passed since the last user activity (mouse movement, keyboard keys pressed)
from ctypes import Structure, windll, c_uint, sizeof, byref
import time
class LASTINPUTINFO(Structure):
_fields_ = [
('cbSize', c_uint),
('dwTime', c_uint),
]
def get_idle_duration():
lastInputInfo = LASTINPUTINFO()
lastInputInfo.cbSize = sizeof(lastInputInfo)
windll.user32.GetLastInputInfo(byref(lastInputInfo))
millis = windll.kernel32.GetTickCount() - lastInputInfo.dwTime
return millis / 1000.0
for i in range(10):
print get_idle_duration()
time.sleep(1)
Problem: However, running this script prints out the following when no user input is being made during the execution of the script:
0.109
0.047
0.203
0.124
0.093
0.031
0.187
0.125
0.062
0.0
Why does the idle time printed out not continue to increase, but rather looks like it is being reset continuously?