I tried a work around with alt-tab as in the code section. But it's slow, I had to slow it down so much for it to work. It also doesn't work well with Edge browser tabs. It's a little buggy overall. Maybe more verification checks would improve it. But I'd rather use WinActivate as it's fast and simple to use.
Code: Select all
altTab(matchTitle) {
a := GetAltTabWindows()
for index, value in a {
WinGetTitle, OutputVar, AHK_id %value%
FoundPos := InStr(OutputVar, matchTitle)
If (FoundPos == 1) {
a := 0
s := "{Alt Down}"
index -= 1
Loop, %index% {
s .= "{Tab}"
}
s .= "{Alt Up}"
delay := A_KeyDelay
duration := A_KeyDuration
SetKeyDelay, 500, 1
SendEvent, %s%
SetKeyDelay, delay, duration
Return
}
}
}
GetAltTabWindows() { ; teadrinker https://www.autohotkey.com/boards/viewtopic.php?p=344440#p344440
AltTabList := []
WinGet, list, List
Loop % list
if IsAltTabWindow(list%A_Index%)
AltTabList.Push(list%A_Index%)
Return AltTabList
}
IsAltTabWindow(hWnd) {
static GA_ROOTOWNER := 3, WS_EX_APPWINDOW := 0x40000, WS_EX_TOOLWINDOW := 0x80, DWMWA_CLOAKED := 14
if !DllCall("IsWindowVisible", "Ptr", hWnd)
Return false
hOwner := DllCall("GetAncestor", "Ptr", hWnd, "UInt", GA_ROOTOWNER, "Ptr")
hPopup := DllCall("GetLastActivePopup", "Ptr", hOwner, "Ptr")
if (hOwner = hWnd && hPopup != hWnd)
Return false
WinGet, exStyles, ExStyle, ahk_id %hWnd%
;if (exStyles & WS_EX_TOOLWINDOW) && !(exStyles & WS_EX_APPWINDOW)
if (exStyles & 0x8000088) ; WS_EX_TOPMOST | WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE
Return false
DllCall("DwmApi\DwmGetWindowAttribute", "Ptr", hWnd, "UInt", DWMWA_CLOAKED, "UIntP", cloaked, "UInt", 4)
Return !cloaked
}