@winput/window
v1.0.15
Published
Windows window management for Bun - find, move, resize, and manipulate windows
Maintainers
Readme
@winput/window 🪟
Window management for Windows - find, move, resize, and manipulate windows.
Requirements
- OS: Windows 64-bit
- Runtime: Bun (npm not supported)
Installation
bun add @winput/windowUsage
import { window } from "@winput/window";
const notepad = window.findWindow("Notepad");
if (notepad) {
window.activate(notepad);
window.center(notepad);
window.setOpacity(notepad, 0.8);
}
const windows = window.enumWindows();
windows.forEach((w) => console.log(w.title));API
window
Discovery
| Method | Params | Returns | Description |
| ------------------------------------ | ------------------------- | ------------------------------------- | -------------------- |
| getActiveWindow() | - | WindowInfo \| null | Get focused window |
| findWindow(title) | string | HWND \| null | Find by title |
| waitForWindow(title, timeout?) | string, number | Promise<HWND \| null> | Wait for window |
| waitForWindowClose(hwnd, timeout?) | HWND, number | Promise<boolean> | Wait for close |
| enumWindows() | - | WindowInfo[] | List visible windows |
| enumChildWindows(parent) | HWND | WindowInfo[] | List children |
| getList() | - | HWND[] | Get all HWNDs |
| getCount() | - | number | Count windows |
Properties
| Method | Params | Returns | Description |
| ----------------------------- | --------------- | ------------------------------- | --------------- |
| getWindowTitle(hwnd) | HWND | string | Get title |
| getWindowRect(hwnd) | HWND | Rect | Get bounds |
| getClientRect(hwnd) | HWND | Rect | Get client area |
| getWindowSize(hwnd) | HWND | Size | Get size |
| getClientSize(hwnd) | HWND | Size | Get client size |
| getClassName(hwnd) | HWND | string | Get class name |
| getWindowProcessId(hwnd) | HWND | number | Get PID |
| getProcessPath(hwnd) | HWND | string | Get exe path |
| getProcessName(hwnd) | HWND | string | Get exe name |
| getExtendedWindowInfo(hwnd) | HWND | ExtendedInfo | Detailed info |
| getText(hwnd) | HWND | string | All window text |
State
| Method | Params | Returns | Description |
| ------------------------- | --------------- | -------------- | -------------- |
| isWindow(hwnd) | HWND | boolean | Handle valid |
| isWindowVisible(hwnd) | HWND | boolean | Is visible |
| isWindowMinimized(hwnd) | HWND | boolean | Is minimized |
| isWindowMaximized(hwnd) | HWND | boolean | Is maximized |
| getMinMax(hwnd) | HWND | -1 \| 0 \| 1 | Min/Normal/Max |
| getStyle(hwnd) | HWND | number | Style flags |
| getExStyle(hwnd) | HWND | number | Extended style |
Actions
| Method | Params | Returns | Description |
| ---------------------- | --------------- | --------- | ----------------- |
| activate(hwnd) | HWND | boolean | Focus and restore |
| focusWindow(hwnd) | HWND | boolean | Bring to front |
| showWindow(hwnd) | HWND | boolean | Show window |
| hideWindow(hwnd) | HWND | boolean | Hide window |
| minimizeWindow(hwnd) | HWND | boolean | Minimize |
| maximizeWindow(hwnd) | HWND | boolean | Maximize |
| restoreWindow(hwnd) | HWND | boolean | Restore |
| closeWindow(hwnd) | HWND | boolean | Close |
| kill(hwnd) | HWND | boolean | Force kill |
| flashWindow(hwnd) | HWND | boolean | Flash taskbar |
| minimizeAll() | - | void | Minimize all |
Manipulation
| Method | Params | Returns | Description |
| ------------------------------ | --------------------------- | --------- | ---------------- |
| moveWindow(hwnd, x, y, w, h) | HWND, number×4 | boolean | Move/resize |
| center(hwnd) | HWND | boolean | Center on screen |
| setOpacity(hwnd, opacity) | HWND, number | boolean | Set transparency |
| setTopmost(hwnd, enable) | HWND, boolean | boolean | Always on top |
| setEnabled(hwnd, enabled) | HWND, boolean | boolean | Enable/disable |
| setTitle(hwnd, title) | HWND, string | boolean | Change title |
| moveToTop(hwnd) | HWND | boolean | Top Z-order |
| moveToBottom(hwnd) | HWND | boolean | Bottom Z-order |
| redraw(hwnd) | HWND | boolean | Force repaint |
Coordinates
| Method | Params | Returns | Description |
| ---------------------------- | ----------------------------------- | ----------------- | --------------- |
| clientToScreen(hwnd, x, y) | HWND, number, number | Point | Client → screen |
| screenToClient(hwnd, x, y) | HWND, number, number | Point | Screen → client |
Wait
| Method | Params | Returns | Description |
| ------------------------------- | ------------------------- | ------------------ | ------------- |
| waitActive(hwnd, timeout?) | HWND, number | Promise<boolean> | Wait active |
| waitNotActive(hwnd, timeout?) | HWND, number | Promise<boolean> | Wait inactive |
Regions
| Method | Params | Returns | Description |
| ------------------------------------------- | ------------------------------------ | --------- | ------------ |
| setRegion.rect(hwnd, x, y, w, h) | HWND, number×4 | boolean | Rectangle |
| setRegion.ellipse(hwnd, x, y, w, h) | HWND, number×4 | boolean | Ellipse |
| setRegion.round(hwnd, x, y, w, h, rw, rh) | HWND, number×6 | boolean | Rounded rect |
| setRegion.polygon(hwnd, points) | HWND, Point[] | boolean | Polygon |
| setRegion.reset(hwnd) | HWND | boolean | Reset |
Types
HWND
type HWND = number; // Window handleWindowInfo
{
hwnd: number;
title: string;
rect: Rect;
className: string;
processId: number;
}Rect
{
left: number;
top: number;
right: number;
bottom: number;
}Size
{
width: number;
height: number;
}Point
{
x: number;
y: number;
}ExtendedInfo
{
hwnd: number;
title: string;
className: string;
processId: number;
processName: string;
rect: Rect;
clientRect: Rect;
isVisible: boolean;
isMinimized: boolean;
isMaximized: boolean;
}Exports
| Export | Type | Description |
| ------------ | --------------------------- | ---------------------- |
| window | Window | Main window operations |
| WindowInfo | WindowInfo | Window information |
| Rect | Rect | Rectangle bounds |
