Hi guys, I had this problem for the last several days.
I have a script that executes some timers and if (timer > value) + (computer has been idle > value ) then it should execute something.
What messes up everything is when windows goes to sleep/hibernate. Idle timers continue to run while the pc sleeps and on waking up windows the script triggers when it shouldn't.
The solution in the post above didn't work for me, the powerbroadcast = 536 didn't work on Windows 10.
I also read in another post that it's possible to fetch the windows even registry and find out the system resume time, but it was too complicated for my abilities and I didn't find any working example. So here is what I came up with, hoping that it will help anyone in my situation:
First workaround that I found:
Trigger only if idle time is between target time and target time + 1 second.
Let's say after 2 hours that the computer is idle you want to trigger a script. 2 hours = 7200 seconds.
If $mytimer > value and $idletime >7200 and $Idletime <7201 seconds Then
Execute what you want
sleep 3 seconds (to avoid repeating triggers if the script reloads in < 1 second)
EndIf
This means that if you hibernate windows and resume let's say after 3 hours, the 3rd condition won't be met and when you move the mouse the counter will resume from 0.
But: this is not elegant 😛
FINAL SOLUTION that I found later:
What I did:
Created a new au3 script. Only 1 instruction: Sleep 120 seconds. Called it: system_just_resumed.exe
This script is triggered by the windows task scheduler on system logon and on system resume after hybernation/sleep.
What I did in my main script:
If $mytimer > value and $idletime >7200 and Not ProcessExists("system_just_resumed.exe") Then
Execute what you want
EndIf
Rationale: even if the pc has been idle while sleeping, the execution will be blocked by the system_just_resumed script for 2 minutes after resuming windows..
Which means: I have 2 minutes to move the mouse/keyboard after resuming the system to avoid a false trigger.
Hope this helps someone with my same problem I had.
Ps: in task scheduler, in order to trigger the exe file on system resume: