Skip to content

Instantly share code, notes, and snippets.

@andymasteroffish
Last active December 22, 2025 22:42
Show Gist options
  • Select an option

  • Save andymasteroffish/41a02deb5d2924dadb4e3c005e564b8f to your computer and use it in GitHub Desktop.

Select an option

Save andymasteroffish/41a02deb5d2924dadb4e3c005e564b8f to your computer and use it in GitHub Desktop.
AutHotkey script for launching arcade games
#Persistent
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Relaunch Game on Crash or Close
; by Andy Wallace
; andymakes.com
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Make sure to specify the window_title and program_path
; Press Win-Z while this is running to kill it
: Note: there is no indicator that it has stopped, but it has
;
; This script requires AutoHotkey 1 (not 2)
; Here is a version it has been tested with:
; https://www.autohotkey.com/download/1.1/AutoHotkey_1.1.37.02_setup.exe
;
; This scripts was cobbled together from other scripts along with some original work
; Shout-out to babycastles for writing the earliest script that this was based on
;
; modify this and do whatever with it
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Set the title and path to your game
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; The title must be exactly the title of the window (shown at the top when windowed)
; The path must be the full path to your exe
window_title := "hypnogenesis"
program_path := "C:\Users\andy_\Desktop\killme\hypno_0.3b_mag_2026_win\VIDEO_WAAAVES_2_718.exe"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Options
; You can keep these as default if you want
; Explanation for each option is a little lower in the comments
; All timing is in milliseconds
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
check_interval := 10000
hide_cursor := false
press_enter := false
press_enter_delay := 5000
wiggle_and_click := false
wiggle_and_click_interval := 5000
kill_others := false
reset_key_enabled := false
reset_key := "K"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Options Info
; Here's what the above options do
;
; check_interval : frequency in milliseconds between checks to see if the window is open. This number should be longer than it takes for your game to launch.
;
; hide_cursor : if true, the mouse will be hidden. You'll get it back when you exit the autohotkey script.
;
; press_enter : if true, after launching the game, the script will wait press_enter_delay milliseconds and then send an ENTER keystroke. This is useful for launching old Unity games.
;
; wiggle_and_click : if true, every wiggle_and_click_interval the mouse will move slightly and then left-click. Useful if your game doesn't get focus on launch (and doesn't care about the mouse).
;
; kill_others : if true, all other windows will be closed right before the game is launched. Useful if stuff ever gets left open somehow. Be careful with this! EVERYTHING will be closed and unsaved work will be lost.
;
; reset_key_enabled : if true, pressing this key will relaunch the game. This can be useful if kill_others is set as it can act as a hard reset if your game freezes. It will close the window and relaunch. Note: using this setting without kill_others will result in your game being launched on top of itself
; reset_key can be formatted like "F2" or "a" or "A" (it should have quotes)
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Actual code starts here
; Feel free to mess with it if you need to
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Monitor the program
SetTimer, CheckProgram, %check_interval%
;set the mouse to move every so often
if(wiggle_and_click){
SetTimer, MoveMouse, %wiggle_and_click_interval%
}
SetTitleMatchMode, 2 ; Allow partial matches on window titles
; reset key
if(reset_key_enabled){
Hotkey, %reset_key%, ResetFunction
}
; Exit the script when Win+Z is pressed
#z::
ShowCursor() ; Restore the cursor
; MsgBox, "goodbye, friend"
ExitApp
ResetFunction:
LaunchGame()
return
; The meat of the program: the loop that looks for the game and relaunches
CheckProgram:
; Check if the window exists
IfWinNotExist, %window_title%
{
LaunchGame()
}
return
LaunchGame(){
; autohotkey functions need to be explictly told about variables
global hide_cursor
global press_enter
global press_enter_delay
global kill_others
global window_title
global program_path
; kill all windows if we are supposed to
if(kill_others){
KillAllWindows()
}
; Launch the program
Run, %program_path%,,
; wait and press enter if we're supposed to
if(press_enter){
Sleep %press_enter_delay%
Send {Enter}
}
; hide the mouse if we're supposed to
if(hide_cursor){
HideCursor()
}
}
; Function to move and click the mouse
MoveMouse(){
mousemove 5, 5, 10, R
mousemove -5, -5, 10, R
;click the mouse incase the current game does not have focus
CoordMode, Mouse, Screen
MouseClick, left, 960, 540
}
; This loop runs through and closes everything other than system files
KillAllWindows(){
;https://autohotkey.com/board/topic/69677-close-all-windows-openminimized-browsers-but-not-pwr-off/
WinGet, id, list,,, Program Manager
Loop, %id%
{
this_id := id%A_Index%
WinActivate, ahk_id %this_id%
WinGetClass, this_class, ahk_id %this_id%
WinGetTitle, this_title, ahk_id %this_id%
;MsgBox, %this_title%
If(This_class != "Shell_traywnd") && (This_class != "Button") ; If class is not Shell_traywnd and not Button
WinClose, ahk_id %this_id%
;This is what it should be ;MsgBox, This ahk_id %this_id% ; Easier to test ;)
}
}
; Function to hide the cursor
HideCursor() {
SystemCursor("Hide")
}
; Function to show the cursor
ShowCursor() {
SystemCursor("Show")
}
; Utility function to manipulate the system cursor
SystemCursor(action) {
static hCursor
if (action = "Hide") {
hCursor := DllCall("LoadCursor", "Ptr", 0, "Int", 32512, "Ptr") ; IDC_ARROW
DllCall("SetSystemCursor", "Ptr", hCursor, "Int", 32512)
DllCall("SetSystemCursor", "Ptr", hCursor, "Int", 32513) ; IDC_IBEAM
DllCall("SetSystemCursor", "Ptr", hCursor, "Int", 32514) ; IDC_WAIT
DllCall("SetSystemCursor", "Ptr", hCursor, "Int", 32515) ; IDC_CROSS
DllCall("SetSystemCursor", "Ptr", hCursor, "Int", 32516) ; IDC_UPARROW
DllCall("SetSystemCursor", "Ptr", hCursor, "Int", 32517) ; IDC_SIZE
} else if (action = "Show") {
DllCall("SystemParametersInfo", "UInt", 0x57, "UInt", 1, "UInt", 0, "UInt", 0)
}
}
; if you're using this script you better support Palestine and trans rights
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment