Cycle through windows of all open applications Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kocelac205
Posts: 24
Joined: 04 Jul 2021, 01:15

Cycle through windows of all open applications

Post by kocelac205 » 26 Nov 2021, 13:34

there are a couple of keyboard shortcuts tht allows you to do this

alt+tab and win+tab opens up the task view like page from where you can select the desired window
alt+esc lets you cycle through all the open windows..but this ignores minimized windows

i want to able to cycle through windows irrespective of whether window is minimized or in the background without bringing up the task view page when i use mouse wheel up or down preferably in the last used order..so its a weird combination of both...it wud be great if somebody can guide me on this..maybe i am overlooking some other keyboard shortcut??
any help wud be great

PS: wud it be possible to activate the script only if mouse wheel is scrolled when mouse is at any corner of the screen???

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Cycle through windows of all open applications

Post by mikeyww » 26 Nov 2021, 15:55

Here is a demonstration that you can adapt.

Code: Select all

F3::
win := windows()
WinActivate, % "ahk_id " win[win.Count()]
Return

windows() {
 program := []
 WinGet, wins, List
 Loop, %wins% {
  WinGet, style, Style, % "ahk_id " wins%A_Index%
  If !(style ~= "0x(9|16)")
   program.Push(wins%A_Index%)
 }
 Return program
}

kocelac205
Posts: 24
Joined: 04 Jul 2021, 01:15

Re: Cycle through windows of all open applications

Post by kocelac205 » 27 Nov 2021, 05:36

thank you..would it be possible to cycle through it in the reverse order also??

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Cycle through windows of all open applications

Post by mikeyww » 27 Nov 2021, 07:20

Code: Select all

F3:: ; Move bottom window to top
F4:: ; Move top window to bottom
win := []
WinGet, wins, List
Loop, %wins% {
 WinGet, style, Style, % "ahk_id " wins%A_Index%
 If !(style ~= "0x(9|16)")
  win.Push(wins%A_Index%)
}
If (A_ThisHotkey = "F4") {
 WinSet, Bottom,  , % "ahk_id " win.1
 WinActivate      , % "ahk_id " win.2
} Else WinActivate, % "ahk_id " win[win.Count()]
Return

kocelac205
Posts: 24
Joined: 04 Jul 2021, 01:15

Re: Cycle through windows of all open applications

Post by kocelac205 » 28 Nov 2021, 10:38

i tried the above script with 4 windows open...after cycling through all the tabs once only 2 windows got cycled through in the next cycle...if i restart the script again it cycles through all the tabs in the first cycle but if you try to continue to cycle again only 2 of the 4 gets cycled..is this some kind of issue with matching the window title or somethig??

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Cycle through windows of all open applications

Post by mikeyww » 28 Nov 2021, 10:41

It worked here, but you may need to adjust it to see which windows are matching at your end, etc. You might have windows in the array that should not be there. The version below will display the window titles.

Code: Select all

F3:: ; Move bottom window to top
F4:: ; Move top window to bottom
win := [], list := ""
WinGet, wins, List
Loop, %wins% {
 WinGet, style, Style, % winTitle := "ahk_id " wins%A_Index%
 If (style ~= "0x(9|16)")
  Continue
 WinGetTitle, ttitle, %winTitle%
 win.Push(wins%A_Index%), list .= (list ? "`n`n" : "") ttitle
}
MsgBox, 64, % "Window list (N=" win.Count() ")", %list%
If (A_ThisHotkey = "F4") {
 WinSet, Bottom,  , % "ahk_id " win.1
 WinActivate      , % "ahk_id " win.2
} Else WinActivate, % "ahk_id " win[win.Count()]
Return

kocelac205
Posts: 24
Joined: 04 Jul 2021, 01:15

Re: Cycle through windows of all open applications

Post by kocelac205 » 28 Nov 2021, 12:32

thank you for the script showing all the window names...i am not sure wht the issue is..maybe its some bug in collecting window names..ill try to explain wht happened in my case..i had 5 windows open brave browser, notepad++,file explorer, internet download manager, potplayer..
the first time the script is run all the five windows were listed...as i cycle through it and reach internet download manager, internet download manager alone gets removed from the list...again as i cycle through it and reach potplayer it also gets removed...currently i am facing the issue onl with idm and potplayer..
also if 2 or more windows of same application is open it only shows 1 window only per application

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Cycle through windows of all open applications

Post by mikeyww » 28 Nov 2021, 13:08

An update is below.

Code: Select all

F3:: ; Move bottom window to top
F4:: ; Move top window to bottom
win := []
WinGet, wins, List
Loop, %wins% {
 WinGetTitle, ttitle, % winTitle := "ahk_id " wins%A_Index%
 WinGet, proc, ProcessName, %winTitle%
 WinGetClass, class, %winTitle%
 If (ttitle > "" && (ttitle != "Program Manager" || proc != "Explorer.EXE") && class != "#32770")
  win.Push(wins%A_Index%)
}
If (A_ThisHotkey = "F4") {
 WinSet, Bottom,  , % "ahk_id " win.1
 WinActivate      , % "ahk_id " win.2
} Else WinActivate, % "ahk_id " win[win.Count()]
Return

kocelac205
Posts: 24
Joined: 04 Jul 2021, 01:15

Re: Cycle through windows of all open applications

Post by kocelac205 » 28 Nov 2021, 13:45

is there an alternative way to get window titles??the code posted above cycles through lot of stuff including rainmeter skins tht i have on desktop..
i apologize for all the hassle

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Cycle through windows of all open applications

Post by mikeyww » 28 Nov 2021, 13:48

You can add to line 10-11, to eliminate what you do not need.

Code: Select all

F3:: ; Move bottom window to top
F4:: ; Move top window to bottom
win := []
WinGet, wins, List
Loop, %wins% {
 WinGetTitle, ttitle, % winTitle := "ahk_id " wins%A_Index%
 WinGet, proc, ProcessName, %winTitle%
 SplitPath, proc,,,, proc
 WinGetClass, class, %winTitle%
 If (ttitle > "" && (ttitle != "Program Manager" || proc != "Explorer") && class != "#32770")
  If proc not in Rainmeter
   win.Push(wins%A_Index%)
}
If (A_ThisHotkey = "F4") {
 WinSet, Bottom,  , % "ahk_id " win.1
 WinActivate      , % "ahk_id " win.2
} Else WinActivate, % "ahk_id " win[win.Count()]
Return

Archie2022
Posts: 25
Joined: 06 May 2022, 03:16

Re: Cycle through windows of all open applications

Post by Archie2022 » 17 Jun 2022, 10:15

mikeyww wrote:
26 Nov 2021, 15:55
Here is a demonstration that you can adapt.

Code: Select all

F3::
win := windows()
WinActivate, % "ahk_id " win[win.Count()]
Return

windows() {
 program := []
 WinGet, wins, List
 Loop, %wins% {
  WinGet, style, Style, % "ahk_id " wins%A_Index%
  If !(style ~= "0x(9|16)")
   program.Push(wins%A_Index%)
 }
 Return program
}
Is there a way to modify this code to cycle through non-minimized windows? This maximize all windows.


Archie2022
Posts: 25
Joined: 06 May 2022, 03:16

Re: Cycle through windows of all open applications

Post by Archie2022 » 18 Jun 2022, 04:08

mikeyww wrote:
17 Jun 2022, 10:47
Here is a way to identify min-max state. https://www.autohotkey.com/docs/commands/WinGet.htm#MinMax
Thank you but I know that part, the issue is that I am not sure where to put an "if" in that code as it is not understandable for me, I am not that knowledgeable in ahk yet

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Cycle through windows of all open applications

Post by mikeyww » 18 Jun 2022, 05:42

Code: Select all

F3:: ; Move bottom window to top
F4:: ; Move top window to bottom
win := []
WinGet, wins, List
Loop, %wins% {
 WinGetTitle, ttitle, % winTitle := "ahk_id " wins%A_Index%
 WinGet, proc, ProcessName, %winTitle%
 WinGet, state, MinMax, %winTitle%
 SplitPath, proc,,,, proc
 WinGetClass, class, %winTitle%
 If (ttitle > "" && (ttitle != "Program Manager" || proc != "Explorer") && class != "#32770" && state != -1)
  If proc not in Rainmeter
   win.Push(wins%A_Index%)
}
If (A_ThisHotkey = "F4") {
 WinSet, Bottom,  , % "ahk_id " win.1
 WinActivate      , % "ahk_id " win.2
} Else WinActivate, % "ahk_id " win[win.Count()]
Return

Archie2022
Posts: 25
Joined: 06 May 2022, 03:16

Re: Cycle through windows of all open applications  Topic is solved

Post by Archie2022 » 19 Jun 2022, 02:00

mikeyww wrote:
18 Jun 2022, 05:42

Code: Select all

F3:: ; Move bottom window to top
F4:: ; Move top window to bottom
win := []
WinGet, wins, List
Loop, %wins% {
 WinGetTitle, ttitle, % winTitle := "ahk_id " wins%A_Index%
 WinGet, proc, ProcessName, %winTitle%
 WinGet, state, MinMax, %winTitle%
 SplitPath, proc,,,, proc
 WinGetClass, class, %winTitle%
 If (ttitle > "" && (ttitle != "Program Manager" || proc != "Explorer") && class != "#32770" && state != -1)
  If proc not in Rainmeter
   win.Push(wins%A_Index%)
}
If (A_ThisHotkey = "F4") {
 WinSet, Bottom,  , % "ahk_id " win.1
 WinActivate      , % "ahk_id " win.2
} Else WinActivate, % "ahk_id " win[win.Count()]
Return
thank you very much

Post Reply

Return to “Ask for Help (v1)”