@bun-win32/uiautomationcore
v2.0.1
Published
Zero-dependency, zero-overhead Win32 UIAUTOMATIONCORE bindings for Bun (FFI) on Windows.
Downloads
401
Maintainers
Readme
@bun-win32/uiautomationcore
Zero-dependency, zero-overhead Win32 UIAutomationCore bindings for Bun on Windows.
Overview
@bun-win32/uiautomationcore exposes the documented flat uiautomationcore.dll exports using Bun's FFI. It provides a single class, UIAutomationCore, which lazily binds native symbols on first use. You can optionally preload a subset or all symbols up-front via Preload().
The bindings are strongly typed for a smooth DX in TypeScript.
Features
- Bun-first ergonomics on Windows 10/11.
- Direct FFI to
uiautomationcore.dll(UI Automation nodes, pattern objects, provider bridging, and event plumbing). - In-source docs in
structs/UIAutomationCore.tswith links to Microsoft Learn. - Lazy binding on first call; optional eager preload (
UIAutomationCore.Preload()). - No wrapper overhead; calls map 1:1 to native APIs.
- Strongly-typed Win32 aliases (see
types/UIAutomationCore.ts).
Requirements
- Bun runtime
- Windows 10 or later
Installation
bun add @bun-win32/uiautomationcoreQuick Start
import UIAutomationCore from '@bun-win32/uiautomationcore';
UIAutomationCore.Preload(['UiaClientsAreListening', 'UiaGetRootNode', 'UiaNodeRelease']);
console.log('UIA clients listening:', UIAutomationCore.UiaClientsAreListening() !== 0);
const rootNodeBuffer = Buffer.alloc(8);
const result = UIAutomationCore.UiaGetRootNode(rootNodeBuffer.ptr!);
if (result !== 0) {
throw new Error(`UiaGetRootNode failed: 0x${(result >>> 0).toString(16).padStart(8, '0')}`);
}
const rootNode = rootNodeBuffer.readBigUInt64LE(0);
try {
console.log('Root node handle:', `0x${rootNode.toString(16)}`);
} finally {
void UIAutomationCore.UiaNodeRelease(rootNode);
}[!NOTE] AI agents: see
AI.mdfor the package binding contract and source-navigation guidance. It explains how to use the package without scanning the entire implementation.
Examples
Run the included examples:
bun run example:focus-radar # animate UIA availability for the foreground window
bun run example:pattern-probe # inspect common pattern providers on the active windowNotes
- Either rely on lazy binding or call
UIAutomationCore.Preload(). VARIANTandUiaPointparameters are modeled as caller-packed buffers; allocate the native layout locally and pass.ptr.- Windows only. Bun runtime required.
- SAL types & naming: nullability is in the type —
Optional<T>(formally optional, SAL_*opt_) andNullable<T>(plain[in]/[out]the docs say can be NULL), the null sentinel derived fromT(nullfor pointersLP*/P*,0nfor handles/by-value addresses); direction is in the parameter name —_out(_Out_),_in_out(_Inout_),_In_bare. SeeAI.mdand the repoAGENTS.md.
