Skip to content

Instantly share code, notes, and snippets.

@snowman
Last active July 6, 2021 14:58
Show Gist options
  • Save snowman/a82bb832c4a2e0b3d89bbc9a1d2c7231 to your computer and use it in GitHub Desktop.
Save snowman/a82bb832c4a2e0b3d89bbc9a1d2c7231 to your computer and use it in GitHub Desktop.
AutoHotkey - Switch windows with same process name
#SingleInstance Force
#Persistent
DetectHiddenWindows, Off
;; Description
;;
;; This AutoHotkey script is to switch between different windows of the same process name.
;;
;; The checking algorithm is based on the app's process basename without path.
;;
;; It works well with regular Window apps, Explorer, Chrome, etc
;; Usage
;;
;; Activate NEXT window of same process name
;; of the current active app with "Alt + `"
!`::
WinGet, activeProcess, ProcessName, A
;; The command below create pseudo array like windowList<index>,
;; and windowList is the count of total window found.
;;
;; windowList = 2 ;; two window
;; windowList1 = 0xHEX_VALUE; ;; first window
;; windowList2 = 0xHEX_VALUE; ;; second window
WinGet, windowList, List, ahk_exe %activeProcess%
windowCount := windowList
If windowCount > 1
{
If (activeProcess = "explorer.exe") {
Loop, % windowCount {
rIndex := windowCount + 1 - A_Index
WinGetClass, sClass, % "ahk_id " windowList%rIndex%
If (sClass = "CabinetWClass") {
WinActivate, % "ahk_id " windowList%rIndex%
break
}
}
} Else {
WinActivate, % "ahk_id " windowList%windowCount%
}
}
Return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment