Skip to content

Instantly share code, notes, and snippets.

@RJNY
Last active April 20, 2026 15:29
Show Gist options
  • Select an option

  • Save RJNY/a1eaf1ca640ae654401f3995221f5a5a to your computer and use it in GitHub Desktop.

Select an option

Save RJNY/a1eaf1ca640ae654401f3995221f5a5a to your computer and use it in GitHub Desktop.
Apollo Pause/Resume AHK Scripts

Warning

This is a Work in Progress! I am actively testing and updating this script as I run into bugs.

To get unstuck, the answer is almost always to run the resume.ahk script manually.

If that doesn't work, please feel free to share your use case only if you're able to reliably reproduce it.

How to Use:

https://github.com/ClassicOldSong/Apollo/wiki/Auto-pause-resume-games

Description of each script

Pause

  • grabs whatever window is in the foreground an minimizes it. it will grab the PID so it know what to wake up later

Resume

  • Reads the temp file, takes the PID, unfreezes and restores the minimized window.

Known issues

  1. If game is in Fullscreen mode, the minimize action will not work. This keeps the PC awake.
  2. If apollo force closes during a pause, and the resume script doesn't run, you must manually run the resume.ahk script.
  3. No other known issues at this time.
#Requires AutoHotkey v2.0
#SingleInstance Force
DetectHiddenWindows true
global IsProcessSuspended := false
global IntentionalExit := false
global Debug := false
StateFile := A_Temp "\AutoPauseResume.state"
OnExit(Cleanup)
if FileExist(StateFile)
FileDelete(StateFile)
LockFile := A_Temp "\AutoPauseResume.lock"
if FileExist(LockFile)
FileDelete(LockFile)
ExcludedProcesses := Map(
"explorer.exe", true,
"csrss.exe", true,
"winlogon.exe", true,
"svchost.exe", true,
"dwm.exe", true,
"cmd.exe", true,
"chrome.exe", true,
"powershell.exe", true,
"sublime_text.exe", true,
"sublime_merge.exe", true,
"steam.exe", true,
"steamwebhelper.exe", true,
"openconsole.exe", true,
"windowsterminal.exe", true,
"playnite.desktopapp.exe", true,
"playnite.fullscreenapp.exe", true,
)
if !WinExist("A")
{
if Debug
MsgBox "No active window detected. Please focus a window to suspend."
ExitApp
}
pid := WinGetPID("A")
if !pid
{
if Debug
MsgBox "Failed to get the active window's PID."
ExitApp
}
processName := WinGetProcessName("ahk_pid " pid)
if !processName
{
if Debug
MsgBox "Failed to retrieve the active window's process name."
ExitApp
}
if ExcludedProcesses.Has(StrLower(processName))
ExitApp
WinMinimize("ahk_pid " pid)
Sleep(200)
if !CallNtProcessFunc(pid, "NtSuspendProcess")
{
if Debug
MsgBox "Failed to suspend process (PID: " pid ")."
ExitApp
}
IsProcessSuspended := true
FileAppend(pid "|" processName, StateFile)
IntentionalExit := true
ExitApp
CallNtProcessFunc(pid, funcName)
{
PROCESS_SUSPEND_RESUME := 0x0800
hProc := DllCall("OpenProcess", "UInt", PROCESS_SUSPEND_RESUME, "Int", 0, "UInt", pid, "Ptr")
if !hProc
return false
hNtdll := DllCall("GetModuleHandle", "Str", "ntdll.dll", "Ptr")
if !hNtdll
{
DllCall("CloseHandle", "Ptr", hProc)
return false
}
pFunc := DllCall("GetProcAddress", "Ptr", hNtdll, "AStr", funcName, "Ptr")
if !pFunc
{
DllCall("CloseHandle", "Ptr", hProc)
return false
}
DllCall(pFunc, "Ptr", hProc)
DllCall("CloseHandle", "Ptr", hProc)
return true
}
Cleanup(exitReason, exitCode)
{
global pid, IsProcessSuspended, IntentionalExit, StateFile
if IsProcessSuspended && !IntentionalExit
{
CallNtProcessFunc(pid, "NtResumeProcess")
if FileExist(StateFile)
FileDelete(StateFile)
}
}
#Requires AutoHotkey v2.0
#SingleInstance Force
StateFile := A_Temp "\AutoPauseResume.state"
if !FileExist(StateFile)
ExitApp
raw := FileRead(StateFile)
if !Trim(raw)
{
FileDelete(StateFile)
ExitApp
}
parts := StrSplit(raw, "|")
pid := Integer(parts[1])
processName := parts[2]
if !ProcessExist(pid)
{
FileDelete(StateFile)
ExitApp
}
if StrLower(ProcessGetName(pid)) != StrLower(processName)
{
FileDelete(StateFile)
ExitApp
}
CallNtProcessFunc(pid, "NtResumeProcess")
Sleep(200)
WinRestore("ahk_pid " pid)
WinActivate("ahk_pid " pid)
FileDelete(StateFile)
ExitApp
CallNtProcessFunc(pid, funcName)
{
PROCESS_SUSPEND_RESUME := 0x0800
hProc := DllCall("OpenProcess", "UInt", PROCESS_SUSPEND_RESUME, "Int", 0, "UInt", pid, "Ptr")
if !hProc
return false
hNtdll := DllCall("GetModuleHandle", "Str", "ntdll.dll", "Ptr")
if !hNtdll
{
DllCall("CloseHandle", "Ptr", hProc)
return false
}
pFunc := DllCall("GetProcAddress", "Ptr", hNtdll, "AStr", funcName, "Ptr")
if !pFunc
{
DllCall("CloseHandle", "Ptr", hProc)
return false
}
DllCall(pFunc, "Ptr", hProc)
DllCall("CloseHandle", "Ptr", hProc)
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment