Skip to content

Instantly share code, notes, and snippets.

@ErikBjare
Created April 17, 2017 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ErikBjare/2d7aab90b90b664798b51a83cce7f325 to your computer and use it in GitHub Desktop.
Save ErikBjare/2d7aab90b90b664798b51a83cce7f325 to your computer and use it in GitHub Desktop.
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