A native Node.js module for listing the currently open application windows on Windows. Can be paired with activate-previous-window to create a task switcher.
It's easy enough to get a list of open windows using the EnumWindows function. The problem is that EnumWindows returns a lot of other things that are not what you would expect: tooltips, background windows, hidden windows, etc. This module uses a few heuristics to filter the list from EnumWindows to include only what you would see when you press Alt+Tab.
npm install @josephuspaye/list-open-windows --save
const { listOpenWindows } = require('@josephuspaye/list-open-windows');
// Get the list of open windows
const windows = listOpenWindows();
// Do something with the list
windows.forEach(console.log);
listOpenWindows()
takes no parameter and returns a list of window objects with the following properties:
handle
(number) the window handle (HWND)zOrder
(number) the window position in z-orderclassName
(string) the window class name, as retrieved from GetClassNamecaption
(string) the window title/caption, as retrieved from GetWindowTextprocessId
(string) the id of the thread that the window belongs to, as retrieved from GetWindowThreadProcessIdprocessPath
(string) the path to the executable of the process that the window belongs to, as retrieved from GetModuleFileNameEx