Hi,
In my AutoHotKey script, how can I specify to focus the previous window that was focused before the current window that is active, without utilizing Alt Tab (Windows Built-in App Switcher)?
Thanks,
Shawn
Focus Previous Window
Re: Focus Previous Window
Code: Select all
F3::
winNumber = 0
WinGet, win, List
Loop, %win% {
WinGetTitle, ttitle, % winTitle := "ahk_id " win%A_Index% ; Window title
WinGet, proc, ProcessName, %winTitle% ; Window process
WinGetClass, class, %winTitle% ; Window class
winNumber += !(class ~= "i)Toolbar|#32770") && ttitle > ""
&& (ttitle != "Program Manager" || proc != "Explorer.exe")
} Until (winNumber = 2)
WinActivate, %winTitle%
Return
Re: Focus Previous Window
Nice, thanks much Mikey!
Would there also be a way to use Alt Tab, but have it simply use AutoHotKey to toggle back and forth between windows? (that it would not show / use the typical Windows Switcher UI / logic)
Would there also be a way to use Alt Tab, but have it simply use AutoHotKey to toggle back and forth between windows? (that it would not show / use the typical Windows Switcher UI / logic)
Re: Focus Previous Window
Yes. !Tab is a valid hotkey.
Re: Focus Previous Window
Thanks Mikey!
In the first post of this thread, I wrote:
How would I modify that code to focus the **next** window, instead of the previous window?
In the first post of this thread, I wrote:
and you replied with:In my AutoHotKey script, how can I specify to focus the previous window that was focused before the current window that is active, without utilizing Alt Tab (Windows Built-in App Switcher)?
Code: Select all
F3::
winNumber = 0
WinGet, win, List
Loop, %win% {
WinGetTitle, ttitle, % winTitle := "ahk_id " win%A_Index% ; Window title
WinGet, proc, ProcessName, %winTitle% ; Window process
WinGetClass, class, %winTitle% ; Window class
winNumber += !(class ~= "i)Toolbar|#32770") && ttitle > ""
&& (ttitle != "Program Manager" || proc != "Explorer.exe")
} Until (winNumber = 2)
WinActivate, %winTitle%
Return
Re: Focus Previous Window
What does "the next window" mean?
Re: Focus Previous Window
For example, if you use Alt Tab (Windows' built-in Windows Switcher), if you keep Alt held down and keep pressing Tab, it continues to goes to the "next" window in the "stack of opened windows."
Re: Focus Previous Window
There are already various AltTab simulators on the forum. viewtopic.php?p=418633#p418633
Re: Focus Previous Window
I honestly don't get how majority of that works, but how do you make it so that you focus on the 2nd previous window though?mikeyww wrote: ↑02 Dec 2021, 09:35Code: Select all
F3:: winNumber = 0 WinGet, win, List Loop, %win% { WinGetTitle, ttitle, % winTitle := "ahk_id " win%A_Index% ; Window title WinGet, proc, ProcessName, %winTitle% ; Window process WinGetClass, class, %winTitle% ; Window class winNumber += !(class ~= "i)Toolbar|#32770") && ttitle > "" && (ttitle != "Program Manager" || proc != "Explorer.exe") } Until (winNumber = 2) WinActivate, %winTitle% Return
Re: Focus Previous Window
It's been a while, but you could fiddle with (winNumber = 2): raise to 3, etc.
Code: Select all
#Requires AutoHotkey v1.1.33
^F2::focus(2)
^F5::focus(3)
focus(nInStack) {
winNumber := 0
WinGet win, List
Loop % win {
WinGetTitle ttitle, % winTitle := "ahk_id " win%A_Index% ; Window title
WinGet proc, ProcessName, %winTitle% ; Window process
WinGetClass class, %winTitle% ; Window class
winNumber += !(class ~= "i)Toolbar|#32770") && ttitle > ""
&& (ttitle != "Program Manager" || proc != "Explorer.exe")
} Until Min(nInStack, win) = winNumber
WinActivate % winTitle
}
Code: Select all
#Requires AutoHotkey v2.0
^F2::focus(2)
^F5::focus(3)
focus(nInStack) {
winNumber := 0
For each, hWnd in list := WinGetList() {
ttitle := WinGetTitle(wTitle := 'ahk_id' hWnd)
class := WinGetClass(wTitle)
proc := WinGetProcessName(wTitle)
winNumber += !(class ~= "i)Toolbar|#32770") && ttitle != ""
&& (ttitle != "Program Manager" || proc != "Explorer.exe")
} Until Min(nInStack, list.Length) = winNumber
WinActivate wTitle
}
Re: Focus Previous Window
Thank you!
Who is online
Users browsing this forum: Google [Bot], Xtra and 119 guests