Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoHotkey: list all open windows

Tags:

autohotkey

WinGet, OutputVar, List can get a list of all unhidden windows. It shows way more than what user can see on the Windows taskbar.

How to limit the window numbers to those shown on the taskbar. Like the simple list in the Task Manager. (Fewer details mode)

like image 934
minion Avatar asked May 09 '19 16:05

minion


1 Answers

Here is one method that is simple, I'm not sure how reliable it is.
It works by trying to minimize the window, if it gets minimized then it means it is available on the taskbar.
You can get the list of found/active windows in any form you need, here I use arrays.

getWindows:

activeWindowsId := []
activeWindowsExe := []
newlist := ""

WinGet, List, List  ;get the list of all windows

Sendinput, #m  ;mimimize all windows by using the windows shortcut win+m
sleep, 200

;Loop % List  ;or use this loop to minimze the windows
;{
;     WinMinimize, % "ahk_id " List%A_Index%
;}

Loop % List
{
    WinGet, theExe, ProcessName, % "ahk_id " List%A_Index%  ;get the name of the exe
    WinGet, windowState, MinMax, % "ahk_id " List%A_Index%  ;get the state of the window, -1 is minimized, 1 is maximized, 0 is neither

    if (windowState == -1)  ;if the window is minimized
    {
        activeWindowsId.push(List%A_Index%) ;add the window id (hwnd) to this array
        activeWindowsExe.push(theExe)  ;add the window exe to this array
        WinRestore, % "ahk_id " List%A_Index%  ;restore the window
    }
}

;read the found active windows list from the array to a string and show it with a msgbox
For index, exe in activeWindowsExe
{
    newList .= exe "`n"
}

msgbox, % newList

return
like image 198
Yane Avatar answered Nov 05 '22 08:11

Yane