Suspend computer after some time idling

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
N_athan
Posts: 40
Joined: 21 Aug 2021, 16:40

Suspend computer after some time idling

23 Sep 2021, 12:47

I did this code to suspend the computer after x minutes, however when I awake the computer it automatic suspend it again :facepalm:

Code: Select all

loop {
   sleep,10
   ;FileAppend, %A_TimeIdle%`n,*

   if (A_TimeIdle > 3000000) {
      command := "rundll32.exe powrprof.dll,SetSuspendState 0,1,0"
      Run, %comspec% /c %command%,, ;Hide
      MsgBox Suspending because IDLE!
      Reload
   }
}
Return
Lf how to improve the code.
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: Suspend computer after some time idling

23 Sep 2021, 13:41

A debugging strategy:
1. Move the MsgBox to occur before the run.
2. Display the value of A_TimeIdle as soon as it is assessed.
3. Show a new MsgBox when the script first loads.
N_athan
Posts: 40
Joined: 21 Aug 2021, 16:40

Re: Suspend computer after some time idling

23 Sep 2021, 15:25

If i set the msgbox to occur first then the run command would never trigger (I'll be probably afk when this happen)
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: Suspend computer after some time idling

23 Sep 2021, 15:29

The MsgBox can still occur after your conditional statement. It might be informative. That is where you can display the value of the idle time, press "OK", and then let your command line run.

In addition, the other two strategies might still be useful in pinpointing the problem. I am wondering whether the script actually reloads, and wondering what the idle time actually is.

I read that if hibernation is enabled, your command line will hibernate the computer. I did not try it. I also read that the following may work, but I did not try it either.

rundll32.exe powrprof.dll, SetSuspendState Sleep

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 111 guests