Skip to content

Instantly share code, notes, and snippets.

@Geczy
Last active April 7, 2023 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Geczy/920c06dc8b135e62e76b27cae1335b0c to your computer and use it in GitHub Desktop.
Save Geczy/920c06dc8b135e62e76b27cae1335b0c to your computer and use it in GitHub Desktop.
; Define a global variable to keep track of the next window index
global NextWindow := 1
; Hotkey: Alt + `
!`::
; Get the process name and ID of the active window
WinGet, ActiveProcessName, ProcessName, A
WinGet, ActiveWindowID, ID, A
; Get a list of all windows associated with the active process
WinGet, WinClassList, List, ahk_exe %ActiveProcessName%
; Get the total number of windows in the list
WinClassCount := WinClassList.Count()
; If there is only one window, do nothing and return
if (WinClassCount <= 1) {
return
}
; Find the next window to activate
while (true) {
; Increment the index for the next window
NextWindow := (NextWindow < WinClassCount) ? (NextWindow + 1) : 1
; Get the HWND (unique identifier) of the next window in the list
NextWindowHWND := WinClassList[NextWindow]
; Skip the active window
if (NextWindowHWND != ActiveWindowID) {
break
}
}
; Bring the next window to the front and activate it
WinSet, Top,, ahk_id %NextWindowHWND%
WinActivate, ahk_id %NextWindowHWND%
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment