Created
April 17, 2017 19:22
-
-
Save ErikBjare/2d7aab90b90b664798b51a83cce7f325 to your computer and use it in GitHub Desktop.
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
import time | |
import ctypes | |
from ctypes import Structure, POINTER, WINFUNCTYPE, windll | |
from ctypes.wintypes import BOOL, UINT, DWORD | |
class LastInputInfo(Structure): | |
_fields_ = [ | |
("cbSize", UINT), | |
("dwTime", DWORD) | |
] | |
# GetLastInputInfo | |
prototype = WINFUNCTYPE(BOOL, POINTER(LastInputInfo)) | |
paramflags = (1, "lastinputinfo"), | |
GetLastInputInfo = prototype(("GetLastInputInfo", ctypes.windll.user32), paramflags) | |
# GetTickCount | |
prototype = WINFUNCTYPE(DWORD) | |
paramflags = () | |
GetTickCount = prototype(("GetTickCount", ctypes.windll.kernel32), paramflags) | |
while True: | |
time.sleep(1) | |
l = LastInputInfo() | |
l.cbSize = ctypes.sizeof(LastInputInfo) | |
GetLastInputInfo(l) | |
#print(l.dwTime/1000) | |
#print(GetTickCount()/1000) | |
seconds_since_input = (GetTickCount() - l.dwTime)/1000 | |
print(seconds_since_input) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment