Get windows idle time without keyboard or mouse input

Hi all,

Please refer below procedure to get windows idle time that refers time without any keyboard or mouse interruption

from ctypes import Structure, windll, c_uint, sizeof, byref

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

def get_idle_duration():
    lastInputInfo = LASTINPUTINFO()
    lastInputInfo.cbSize = sizeof(lastInputInfo)
    millis = windll.kernel32.GetTickCount() - lastInputInfo.dwTime
    return int(millis / 1000.0)


m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
d,h =divmod(h,24)
print "%02d:%02d:%02d:%02d" % (d, h, m, s)

Sample output would be,

20170110-Get-windows-idle-time-without-keyboard-or-mouse-input-event.json (1.09 KB)