Code: Select all
/*
AHK Version 2 power scheme changing code using powrprof.dll OR POWERCFG command-line
Help using information from:
SKAN V2 https://www.autohotkey.com/boards/viewtopic.php?f=83&t=99581&p=444234&hilit=GUID+structure#p444234
noee, HotKeyIt V1 https://www.autohotkey.com/board/topic/61079-powrprofpowergetactivescheme-pointer-to-the-guid/
qwerty12 SvenBent V1 https://www.autohotkey.com/boards/viewtopic.php?t=29779
lmstearn V1 https://www.autohotkey.com/boards/viewtopic.php?t=68530
*/
#Requires AutoHotkey v2.0-a
#Warn VarUnset ;, OutputDebug
#Warn LocalSameAsGlobal ;, OutputDebug
#Warn Unreachable ;, OutputDebug
#SingleInstance
Persistent True
ListLines False ; turn on in specific area to debug
*+!F9:: {
static bufSz := 1024
static GUID_TYPICAL_POWER_SAVINGS := Buffer(16) ; Balanced 381B4222-F694-41F0-9685-FF5BB260DF2E
NumPut "UInt", 0x381B4222, "UShort", 0xF694, "UShort", 0x41F0, "UChar", 0x96, "UChar", 0x85, "UChar", 0xFF
, "UChar", 0x5B, "UChar", 0xB2, "UChar", 0x60, "UChar", 0xDF, "UChar", 0x2E, GUID_TYPICAL_POWER_SAVINGS
static GUID_MIN_POWER_SAVINGS := Buffer(16) ; High Performance 8C5E7FDA-E8BF-4A96-9A85-A6E23A8C635C
NumPut "UInt", 0x8C5E7FDA, "UShort", 0xE8BF, "UShort", 0x4A96, "UChar", 0x9A, "UChar", 0x85, "UChar", 0xA6
, "UChar", 0xE2, "UChar", 0x3A, "UChar", 0x8C, "UChar", 0x63, "UChar", 0x5C, GUID_MIN_POWER_SAVINGS
bufName := Buffer(bufSz)
DllCall("powrprof\PowerGetActiveScheme", "Ptr", 0, "Ptr*", &pGUID := 0)
DllCall("powrprof.dll\PowerReadFriendlyName", "Ptr", 0, "Ptr", pGUID, "Ptr", 0, "Ptr", 0, "Ptr", bufName, "Ptr*", &bufSz) ;sdesc :LPDWORD
DllCall("LocalFree", "Ptr", pGUID, "Ptr")
if (StrGet(bufName) = "Balanced")
{
if DllCall("powrprof\PowerSetActiveScheme", "Ptr", 0, "Ptr", GUID_MIN_POWER_SAVINGS) = 0
TrayTip "AutoHotkey notification.", "High performance power profile active", 17
}
else
{ if DllCall("powrprof\PowerSetActiveScheme", "Ptr", 0, "Ptr", GUID_TYPICAL_POWER_SAVINGS) = 0
TrayTip "AutoHotkey notification.", "Balanced power profile active", 17
}
}
*+!F10:: {
Err := RunWait( A_ComSpec ' /c POWERCFG /GETACTIVESCHEME | FIND /I "381B4222-F694-41F0-9685-FF5BB260DF2E (Balanced)"',, "Min" )
if Err ; ErrorLevel!=0 means string was NOT found
{
Run 'POWERCFG /SETACTIVE 381B4222-F694-41F0-9685-FF5BB260DF2E',, "Hide" ; change profile to (Balanced)
TrayTip "AutoHotkey notification.", "Balanced power profile active", 17
}
else ; ErrorLevel=0 means string WAS found
{
Run 'POWERCFG /SETACTIVE 8C5E7FDA-E8BF-4A96-9A85-A6E23A8C635C',, "Hide" ; change profile to (High performance)
TrayTip "AutoHotkey notification.", "High performance power profile active", 17
}
}