0.1.2 • Published 1 year ago

@josephuspaye/list-open-windows v0.1.2

Weekly downloads
5
License
MIT*
Repository
github
Last release
1 year ago

List Open Windows

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.

Why

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.

Installation

npm install @josephuspaye/list-open-windows --save

Usage

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-order
  • className (string) the window class name, as retrieved from GetClassName
  • caption (string) the window title/caption, as retrieved from GetWindowText
  • processId (string) the id of the thread that the window belongs to, as retrieved from GetWindowThreadProcessId
  • processPath (string) the path to the executable of the process that the window belongs to, as retrieved from GetModuleFileNameEx

Licence

MIT