Tell if Win2000 or XP is inactive

Richie Hindle richie at
Thu Jul 15 17:27:53 CEST 2004

> Would you be prepared to install ctypes and one extra DLL?

Ah!  I hadn't spotted that you were running on Win2000+.  In that case you
can do it with ctypes alone:


import time
from ctypes import *

GetTickCount = windll.kernel32.GetTickCount
GetLastInputInfo = windll.user32.GetLastInputInfo

class LASTINPUTINFO(Structure):
    _fields_ = [("cbSize", c_uint),
                ("dwTime", c_uint)]

lastInputInfo = LASTINPUTINFO()
lastInputInfo.cbSize = sizeof(lastInputInfo)
for i in range(10):
    idleDelta = float(GetTickCount() - lastInputInfo.dwTime) / 1000
    print "Last input event was %.2f seconds ago." % idleDelta


Richie Hindle
richie at

More information about the Python-list mailing list