-
-
Save jamesadney/1882516 to your computer and use it in GitHub Desktop.
idle time on windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
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 | |
while True: | |
time.sleep (2.0) | |
idleness=get_idle_duration() | |
if idleness> 10: | |
print "away (%d sec w/o iteract)"%idleness | |
else: | |
print "active (%d sec w/o iteract)"%idleness |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment