Created
September 16, 2025 09:57
-
-
Save AwesomeLemon/ea98c53886fa5dcc808169e647cc6b72 to your computer and use it in GitHub Desktop.
Switch between instances of a program via Alt + Backtick (Ubuntu-like functionality for Windows)
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
| #Requires AutoHotkey v2.0 | |
| !`:: | |
| { | |
| KEY := "SC029" ; grave/tilde key (backtick) scancode | |
| ; Build candidate list for the current app (special-case Explorer by class) | |
| win_class := WinGetClass("A") | |
| exe := WinGetProcessName("A") | |
| if (exe = "explorer.exe") | |
| win_list := WinGetList("ahk_exe" exe " ahk_class" win_class) | |
| else | |
| win_list := WinGetList("ahk_exe" exe) | |
| if (win_list.Length < 2) | |
| return | |
| ; Start at second-most-recent (index 2). Index 1 is current. | |
| idx := 2 | |
| WinActivate("ahk_id" win_list[idx]) | |
| ; Wait for the initial backtick to be released (debounce) | |
| KeyWait(KEY) | |
| ; While Alt is held, each tap of backtick advances the selection | |
| while GetKeyState("Alt", "P") | |
| { | |
| KeyWait(KEY, "D") ; wait for next press | |
| if !GetKeyState("Alt", "P") | |
| break | |
| if GetKeyState("Shift", "P") | |
| idx := (idx = 1) ? win_list.Length : idx - 1 | |
| else | |
| idx := (idx = win_list.Length) ? 1 : idx + 1 | |
| WinActivate("ahk_id" win_list[idx]) | |
| ; Debounce so one press = one step | |
| KeyWait(KEY) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment