Jump to content

Execute command before sleep


 Share

Recommended Posts

I have a light bulb which I can turn on and off using UDP commands (I already have that working in AutoIt). What I would like to do is run a script before the computer goes to sleep to turn it off, and after it resumes to turn it on. I've already got the latter working, but not the former. I tried Task Scheduler with the kernel power log, but the command doesn't get executed until the computer resumes from sleep. I've tried some things using WM_POWERBROADCAST, but so far I haven't got that to work either. Here's what I've got so far:

Global Const $WM_POWERBROADCAST = 0x218

Global Const $PBT_APMSUSPEND = 0x4
Global Const $PBT_APMRESUMEAUTOMATIC = 0x12

While 1
    Sleep(100)
WEnd

GUICreate("Event Receiver")
GUIRegisterMsg($WM_POWERBROADCAST,"MY_WM_POWERBROADCAST")

Func MY_WM_POWERBROADCAST($hWnd, $uMsg, $wParam, $lParam)
   Switch $wParam
      Case $PBT_APMSUSPEND
         MsgBox(0,"PBT_APMSUSPEND","PBT_APMSUSPEND"&@HOUR&@MIN&@SEC)
      Case $PBT_APMRESUMEAUTOMATIC
         MsgBox(0,"PBT_APMSUSPEND","PBT_APMRESUMEAUTOMATIC"&@HOUR&@MIN&@SEC)
   EndSwitch
EndFunc

Does anyone know how to make this work?

Edited by quadrplax
Clarifying beginning
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...