4 ms·
I'd like to ask the AHK programmers here if anyone can figure out how to do the macOS's CMD+` and CMD+SHIFT+` to alternate between windows of the same App in Wi
by slig 3y ago
I'd like to ask the AHK programmers here if anyone can figure out how to do the macOS's CMD+` and CMD+SHIFT+` to alternate between windows of the same App in Windows while ignoring any minimized window.
I managed to coerce chat GPT to do a working version for the `Last Window`, but it simply cannot do a working forward version.
```
!+`:: ; Last window
WinGet, ActiveProcessName, ProcessName, A
WinGet, windows, List, ahk_exe %ActiveProcessName%
Loop, % windows
{
thisID := windows%A_Index%
WinGet, thisWindowState, MinMax, ahk_id %thisID%
if (thisWindowState = -1)
continue ; Skip if window is minimized
lastWindow := thisID
}
if (lastWindow)
{
WinActivate, ahk_id %lastWindow%
}
return
```
- dattiimo 3y agoI've used GroupAdd[1] and GroupActivate to alternate between windows of the same app but it doesn't ignore minimised windows. Maybe you can ignore minimised when adding to the GroupAdd list some how. [1] https://www.autohotkey.com/docs/v1/lib/GroupAdd.htm https://www.autohotkey.com/docs/v1/lib/GroupAdd.htm
- slig 3y agoThanks! I was going to ask you on your comment, thanks!
- leejoramo 3y agoIf you like macOS keyboard shortcuts, I recommend you checkout Kinto go Windows and Linux. On Windows, Kinto used AHK https://kinto.sh https://kinto.sh However, at least when I set it up Kinto did not provide switching windows in this fashion. Here is the script I use. This includes some related functionality to make the handling of windows more Mac-like ``` ; BRING FORWARD ALL WINDOWS OF THE CURRENT APPLICATION ; This is a generalized version of ; https://superuser.com/questions/113162/bring-to-front-all-windows-for-a-certain-application-in-windows-7#125985 https://superuser.com/questions/113162/bring-to-front-all-wi... ^!`:: WinGetClass, class, A WinGet, id, list, ahk_class %class% Loop, %id% { this_id := id%A_Index% WinActivate, ahk_id %this_id% ; MsgBox, The active window's this_id is "%this_id%". } return ; MINIMIZE ALL WINDOWS OF THE CURRENT APPLICATION ^!m:: WinGetClass, class, A WinGet, id, list, ahk_class %class% Loop, %id% { this_id := id%A_Index% WinMinimize, ahk_id %this_id% } return ; CYCLE ALL WINDOWS OF CURRENT APPLICATION ; Pull bottom window to the top, and force it to display ^`:: ; need Process and Class to restrict to current application ; most apps have unquie window classes, but Chromium based apps ; share their primary window class. Thus Google Chrome, VS Code and ; Electron based apps all looked the same using only `class` WinGet, Active_ID, ID, A WinGet, Active_Process, ProcessName, ahk_id %Active_ID% WinGetClass, class, A WinGet, id, list, ahk_class %class% ahk_exe %Active_Process% lastItem := id%id0% lastItemId := id%lastItem% WinActivate, ahk_id %lastItemId% WinSet, Top,, ahk_id %lastItemId% Winset, AlwaysOnTop, On Winset, AlwaysOnTop, Off return ; CLOSE CURRENT WINDOW AND ACTIVATE NEXT WINDOW OF CURRENT APP ; similar to the CYLCE ALL WINDOWS OF CURRENT APP, but closes the ; current window. ; ; Because some Apps have Tabs that are closed via the same `^w` shortcut, ; we only switch to the next active window if the current window no longer ; exists after sending `^w` ; ; RATIONAL: This makes the Application Context a little more like macOS ; where closing windows leaves you in the current application, and not ; a random window that is the next in the stack. $^w:: ; need Process and Class to restrict to current application ; most apps have unquie window classes, but Chromium based apps ; share their primary window class. Thus Google Chrome, VS Code and ; Electron based apps all looked the same using only `class` WinGet, Active_ID, ID, A WinGet, Active_Process, ProcessName, ahk_id %Active_ID% WinGetClass, class, A WinGet, id, list, ahk_class %class% ahk_exe %Active_Process% lastItem := id%id0% lastItemId := id%lastItem% Send ^w Sleep 50 WinGet, Current_ID, ID, A If (Current_ID != Active_ID) { WinActivate, ahk_id %lastItemId% WinSet, Top,, ahk_id %lastItemId% Winset, AlwaysOnTop, On Winset, AlwaysOnTop, Off } return ```
- slig 3y agoThank you so much!