Monitor Power Scheme Changes

Get help with using AutoHotkey and its commands and hotkeys
1100++
Posts: 78
Joined: 10 Feb 2018, 19:05

Monitor Power Scheme Changes

22 Jan 2019, 15:34

Is there any way for a script to be notified when the power scheme changes?
teadrinker
Posts: 2187
Joined: 29 Mar 2015, 09:41
Contact:

Re: Monitor Power Scheme Changes

22 Jan 2019, 22:22

There is one:

Code: Select all

GUID_POWERSCHEME_PERSONALITY := "245d8541-3943-4422-b025-13a784f679b7"
h := RegisterPowerSettingNotification(GUID_POWERSCHEME_PERSONALITY)
OnExit( Func("UnRegisterNotification").Bind(h) )
OnMessage(0x218, "WM_POWERBROADCAST")
Return

RegisterPowerSettingNotification(GUID) {
   static DEVICE_NOTIFY_WINDOW_HANDLE := 0
   VarSetCapacity(UUID, 16, 0)
   DllCall("Rpcrt4\UuidFromString", Str, GUID, Ptr, &UUID)
   Return DllCall("RegisterPowerSettingNotification", Ptr, A_ScriptHwnd, Ptr, &UUID, UInt, DEVICE_NOTIFY_WINDOW_HANDLE, Ptr)
}

UnRegisterNotification(handle) {
   DllCall("UnregisterPowerSettingNotification", Ptr, handle)
}

WM_POWERBROADCAST(wp, lp) {
   static powerschemes := { "8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c": "GUID_MIN_POWER_SAVINGS"
                          , "a1841308-3541-4fab-bc81-f71556f20b4a": "GUID_MAX_POWER_SAVINGS"
                          , "381b4222-f694-41f0-9685-ff5bb260df2e": "GUID_TYPICAL_POWER_SAVINGS" }

   DllCall("Rpcrt4\UuidToString", Ptr, lp + 16 + 4, PtrP, pStr)
   GUID := StrGet(pStr)
   DllCall("Rpcrt4\RpcStringFree", PtrP, pStr)
   ToolTip % powerschemes[GUID]
}
User avatar
TLM
Posts: 1590
Joined: 01 Oct 2013, 07:52
GitHub: TLMcode
Contact:

Re: Monitor Power Scheme Changes

23 Jan 2019, 20:22

very nice handler!!
1100++
Posts: 78
Joined: 10 Feb 2018, 19:05

Re: Monitor Power Scheme Changes

06 Feb 2019, 01:19

I tried your solution, but, unfortunately, it only seems to monitor changes between different power scheme personalities. The solution I need requires that I be able to distinguish between power schemes that share a personality, so yours won't work.
teadrinker
Posts: 2187
Joined: 29 Mar 2015, 09:41
Contact:

Re: Monitor Power Scheme Changes

06 Feb 2019, 01:54

You can choose what you'd like to monitor here.
1100++
Posts: 78
Joined: 10 Feb 2018, 19:05

Re: Monitor Power Scheme Changes

06 Feb 2019, 15:21

I don't think what I want is listed.

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, Bing [Bot], boiler, braunbaer, roysubs, Xeo786 and 57 guests