@maciejwojs/input-bridge
v0.2.1
Published
Native input bridge addon for Node.js
Downloads
902
Maintainers
Readme
@maciejwojs/input-bridge
Native Node.js addon for simulating hardware input events on Windows and Linux. The package exposes a single JavaScript API for mouse movement, clicks, keyboard events, scrolling, and typed text, with batched execution and optimization support.
Features
- Windows backend using the native
SendInputAPI - Linux backend using the Freedesktop
RemoteDesktopportal on Wayland - Optional Linux X11 backend for environments where Wayland is unavailable
- Batched event queue with explicit
flush()execution - Relative and absolute mouse movement
- Mouse button clicks and wheel scrolling
- Raw keyboard events and typed Unicode text
- DOM
KeyboardEvent.codemapping viakeyPressDOM() - Movement optimization via
optimizeMouseMovesRelative()andoptimizeMouseMovesAbsolute() - Optional native logger callback from the addon
Install
bun installQuick start
import { InputBridge } from '@maciejwojs/input-bridge';
const bridge = new InputBridge({ autoFlush: false });
await bridge.init();
bridge.moveMouseRelative(10, 0);
bridge.mouseClick(0, true);
bridge.mouseClick(0, false);
bridge.flush();API overview
init()- initializes the native bridge and requests permissions on LinuxmoveMouseRelative(x, y)- queue a relative mouse movementmoveMouseAbsolute(x, y)- queue an absolute mouse movementmouseClick(button, down)- queue a mouse button press/releasekeyPress(keyCode, down)- queue a raw keyboard press/releasekeyPressDOM(domCode, down)- queue a scan-code based key event from DOMKeyboardEvent.codescrollMouse(delta)- queue a mouse wheel scroll eventtypeString(text)- queue typed Unicode textoptimizeMouseMovesRelative(distanceThreshold)- reduce buffered relative move eventsoptimizeMouseMovesAbsolute(distanceThreshold)- reduce buffered absolute move eventstoggleOptimization()- enable/disable internal mouse move optimizationflush()- execute all queued input eventssetLogger(callback)- receive native backend log messages
Build and development
bun run build
bun run rebuildTo verify the native addon loads successfully:
bun run test:loadPrebuilt binaries
Create a prebuilt binary for the current platform:
bun run prebuildifyCreate prebuilt binaries for Windows, Linux, and macOS targets:
bun run prebuildify:allBuilt artifacts are placed in prebuilds/ and loaded automatically by lib/index.ts.
Supported platforms
win32- fully implemented with WindowsSendInputlinux- supported on Wayland via the RemoteDesktop portal and optionally on X11 when built with the X11 backend- other OSes use the stub fallback if compiled, but native injection is only available on supported backends
Project layout
lib/- JavaScript API surface and wrapper exportssrc/addon.cpp- N-API bridge implementationsrc/win/platform_input_win.cpp- Windows backendsrc/linux/platform_input_linux.cpp- Linux backendsrc/platform_input_stub.cpp- fallback implementationsrc/platform_input.hpp- shared backend interface and event queuebinding.gyp- native addon build configuration
Notes
The repository is designed to keep the public JS API stable while allowing per-platform native backend extensions. The InputBridge wrapper always exposes the same methods regardless of the active backend.
