Skip to content

Instantly share code, notes, and snippets.

@jeremyfa
Created July 22, 2024 14:42
Show Gist options
  • Save jeremyfa/564644502876041a8b851119b5d9e4ca to your computer and use it in GitHub Desktop.
Save jeremyfa/564644502876041a8b851119b5d9e4ca to your computer and use it in GitHub Desktop.
An AutoHotKey script to switch to the next window of the currently active app (CTRL + TAB)
#Requires AutoHotkey v2.0
; Use Ctrl+Tab to switch between windows of the same application
global windowOrder := Map()
^Tab::
{
; Get the process name and ID of the active window
processName := WinGetProcessName("A")
pid := WinGetPID("A")
; Get a list of all windows for the current process
if (processName == "explorer.exe")
{
windows := WinGetList("ahk_class CabinetWClass")
}
else
{
windows := WinGetList("ahk_pid " pid)
}
if windows.Length = 0
return
; Get the current window ID
currentWindowID := WinExist("A")
; Initialize or update the window order for this process
if !windowOrder.Has(pid) || windowOrder[pid].Length != windows.Length
{
windowOrder[pid] := windows
}
; Find the index of the current window in the order
currentIndex := 0
for index, winId in windowOrder[pid]
{
if winId = currentWindowID
{
currentIndex := index
break
}
}
; Calculate the next window index
nextIndex := currentIndex + 1
if nextIndex > windowOrder[pid].Length
nextIndex := 1
; Activate the next window
WinActivate(windowOrder[pid][nextIndex])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment