Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions ahk/Powerplan.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,10 @@ cmdOnLaunch := "powercfg /s 8fcdad7d-7d71-4ea2-bb4c-158ca7f696de"
; Balanced power plan GUID
cmdOnClose := "powercfg /s 77777777-7777-7777-7777-777777777777"

; Track previous state
fortniteWasRunning := false

Loop {
fortniteIsRunning := WinExist("ahk_exe FortniteClient-Win64-Shipping.exe")

; Only run command when state changes
if (fortniteIsRunning && !fortniteWasRunning) {
Run(cmdOnLaunch, , "Hide")
fortniteWasRunning := true
}
else if (!fortniteIsRunning && fortniteWasRunning) {
Run(cmdOnClose, , "Hide")
fortniteWasRunning := false
}
WinWait("ahk_exe FortniteClient-Win64-Shipping.exe")
Run(A_ComSpec . " /c " . cmdOnLaunch, , "Hide")

DllCall("kernel32.dll\Sleep", "UInt", 5000)
WinWaitClose("ahk_exe FortniteClient-Win64-Shipping.exe")
Run(A_ComSpec . " /c " . cmdOnClose, , "Hide")
Comment on lines +29 to +33
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run() is asynchronous, so if Fortnite opens/closes quickly you can end up with overlapping powercfg invocations and a race where the earlier launch command finishes after the close command (leaving the wrong power plan active). Consider using RunWait() (or capturing the PID and waiting for it to exit) for both powercfg calls to guarantee ordering.

Copilot uses AI. Check for mistakes.
}
Loading