Search code examples
windowsscreensaverautoit

AutoIt: How to get system idle time, or if screensaver is active?


I'd like to have an AutoIt script log the idle time. Alternatively, I'd like to be able to detect when the screensaver is active. There is no function that gives me either of these. How would I go about getting this functionality?


Solution

  • Eh. Found it on a forum.

    #include <Timers.au3>
    
    Global $iLimit = 5 ; idle limit in seconds
    
    HotKeySet("{ESC}", "_Quit")
    
    AdlibRegister("_CheckIdleTime", 500)
    
    While 1
        Sleep(20)
    WEnd
    
    Func _CheckIdleTime()
        If _Timer_GetIdleTime() > $iLimit * 1000 Then MsgBox(16, "Timeout", "You haven't done anything in " & $iLimit & " seconds...  Get busy!", 3)
    EndFunc   ;==>_CheckIdleTime
    
    Func _Quit()
        Exit
    EndFunc   ;==>_Quit