by slig · 3y ago · 0 comments
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
``````
; BRING FORWARD ALL WINDOWS OF THE CURRENT APPLICATION ; This is a generalized version of ; 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
```