Created
October 10, 2024 22:02
-
-
Save vaner-org/557f70fed8c3b8fecac9be8ebe78fb35 to your computer and use it in GitHub Desktop.
AutoHotKey script to open PureRef
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. | |
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. | |
SendMode Input ; Recommended for new scripts due to its superior speed and reliability. | |
; Global variable to store the ID of the window that was active before PureRef | |
global lastActiveWindow := 0 | |
#Up:: ; REPLACE WITH HOTKEY OF CHOICE | |
IfWinExist, ahk_exe PureRef.exe | |
{ | |
WinGet, pureRefState, MinMax, ahk_exe PureRef.exe | |
if (pureRefState == -1) ; If PureRef is minimized | |
{ | |
WinRestore, ahk_exe PureRef.exe | |
WinActivate, ahk_exe PureRef.exe | |
lastActiveWindow := 0 ; Reset lastActiveWindow | |
} | |
else | |
{ | |
IfWinActive, ahk_exe PureRef.exe | |
{ | |
WinMinimize, ahk_exe PureRef.exe | |
AttemptToActivateLastWindow() | |
} | |
else | |
{ | |
WinGetActiveTitle, activeWindow | |
lastActiveWindow := WinExist(activeWindow) | |
WinActivate, ahk_exe PureRef.exe | |
} | |
} | |
} | |
else | |
{ | |
Run, C:\Program Files\PureRef\PureRef.exe ; Replace with the actual path to PureRef | |
} | |
return | |
AttemptToActivateLastWindow() | |
{ | |
if (lastActiveWindow != 0 && WinExist("ahk_id " . lastActiveWindow)) | |
{ | |
WinActivate, ahk_id %lastActiveWindow% | |
} | |
else | |
{ | |
; First fallback: Try to activate any window other than PureRef | |
WinGet, activeList, List,,, Program Manager | |
Loop, %activeList% | |
{ | |
id := activeList%A_Index% | |
WinGetTitle, title, ahk_id %id% | |
WinGet, processName, ProcessName, ahk_id %id% | |
if (processName != "PureRef.exe" && title != "") | |
{ | |
WinActivate, ahk_id %id% | |
return | |
} | |
} | |
; Second fallback: If no other windows, show desktop | |
Send, #d | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment