OnResume() - action when resume from sleep/standby/lock/etc
Posted: 05 Sep 2017, 20:50
this can probably be improved upon by some of you geniuses, but here's a tidy/simple function for running a subroutine when resuming from sleep, standby or hibernate, or unlocking or logging on while running. Lots more options could be added and full wrapping of WM_PowerBroadcast and WM_WTSSession_Change would be better, but in my case this is all I need.
Use:
OnResume( Label [, Delay ] )
where
Label = Subroutine to run
Delay = delay in ms
feedback appreciated
enjoy
- gwarble
Use:
OnResume( Label [, Delay ] )
where
Label = Subroutine to run
Delay = delay in ms
Code: Select all
OnResume(Label,Delay=200,Msg="") {
static Init, Label_, Delay_
If !Init ;first time called
{
DllCall("RegisterSuspendResumeNotification", "ptr", A_ScriptHwnd, "uint", 0)
DllCall( "Wtsapi32.dll\WTSRegisterSessionNotification", "uint", A_ScriptHwnd, "uint", 1 )
OnMessage(0x218, "OnResume") ;WM_POWERBROADCAST
OnMessage(0x2B1, "OnResume") ;WM_WTSSESSION_CHANGE
Label_ := Label
Delay_ := Delay
}
Init := 1
If !IsLabel(Label_)
Return
If (Msg = 0x218)
If (Label=0x7) OR (Label=0x8) OR (Label=0x18) ; PBT_APMRESUMESUSPEND=0x7, PBT_APMRESUMESTANDBY=0x8, PBT_APMRESUMEAUTOMATIC=0x18
SetTimer, %Label_%, -%Delay_%
If (Msg = 0x2B1)
If (Label=0x8) OR (Label=0x5) ; UNLOCK=0x8,LOGON=0x5
SetTimer, %Label_%, -%Delay_%
}
enjoy
- gwarble