Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.