This demo was written in response to a question on the Community Forum.
The user32 API function GetLastInputInfo fills a struct with the tick count at the last session input. You can discover the number of ticks the system was idle by subtracting that number from the value of the current tick count. Use GetTickCount to retrieve the current tick count.
The demo instructs the user to avoid keyboard and mouse input. It uses a timer to activate the routine after five seconds. It gets the current tick count with GetTickCount. It gets the tick count at last user input with GetLastInputInfo. It retrieves the value from the struct. It subtracts the tick count at last input from the current tick count to find out how many ticks (milliseconds) the system has been idle.
struct LASTINPUTINFO,_ cbSize as ulong,_ 'size of struct tickCount as ulong 'tick count at last session input LASTINPUTINFO.cbSize.struct=len(LASTINPUTINFO.struct) print "Please wait and do not touch keyboard or mouse." timer 5000, [getInfo] wait [getInfo] timer 0 calldll #user32, "GetLastInputInfo",_ 'time of last input event LASTINPUTINFO as struct,_ 'struct to hold data result as long 'nonzero=success ticksLastInput=LASTINPUTINFO.tickCount.struct print "Last input tick count: ";ticksLastInput calldll #kernel32, "GetTickCount",_ startTicks as ulong 'ticks since system start print "Ticks since system start ";startTicks print "Idle ticks: ";startTicks-ticksLastInput