Skip to content

Instantly share code, notes, and snippets.

@xgdgsc
Last active February 4, 2022 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xgdgsc/806ec7df51102a2961407bc48c189eef to your computer and use it in GitHub Desktop.
Save xgdgsc/806ec7df51102a2961407bc48c189eef to your computer and use it in GitHub Desktop.
switch power plan based on window name using ahk
#SingleInstance force
#warn
RyzenPowerPlanIDCheck()
{
objShell := ComObjCreate("WScript.Shell")
var := objShell.Exec("cmd /c powercfg /list").StdOut.ReadAll()
global powercfg_ids := ["381b4222-f694-41f0-9685-ff5bb260df2e","a1841308-3541-4fab-bc81-f71556f20b4a"]
for each, id in powercfg_ids
{
IfNotInString, var, %id%
{
msgbox, Looks like we're missing at least one or more Ryzen power plan ids. Didn't find %id% %var%
return
}
}
global powercfg_plan_RyzenBalanced = powercfg_ids[2]
global powercfg_plan_RyzenHighPerf = powercfg_ids[1]
}
RyzenPowerPlanIDCheck()
SetTitleMatchMode, 2
GroupAdd, GAMES_ALL, ahk_class UnityWndClass
GroupAdd, GAMES_ALL, ahk_class vguiPopupWindow
GroupAdd, GAMES_ALL, ahk_class UnrealWindow
GroupAdd, GAMES_ALL, ahk_class UUMAINFORMV40
performance_amd_plan = 0
#Persistent
SetTimer, CheckGame, 10000
; return
CheckGame:
ex := WinExist("ahk_group GAMES_ALL")
; msgbox, %ex%
if (!performance_amd_plan && powercfg_plan_RyzenHighPerf && WinExist("ahk_group GAMES_ALL"))
{
performance_amd_plan = 1
; msgbox, perf 1
Run, powercfg -SETACTIVE %powercfg_plan_RyzenHighPerf%
}
else if (powercfg_plan_RyzenBalanced && performance_amd_plan && !WinExist("ahk_group GAMES_ALL"))
{
; msgbox, perf 2
performance_amd_plan = 0
Run, powercfg -SETACTIVE %powercfg_plan_RyzenBalanced%
}
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment