Skip to content

T-Rumibul/node-native-win-utils

Repository files navigation

License Node-API v8 npm version npm downloads Platform: Windows only

Node Native Win Utils

I did it for myself because I didn't feel like dealing with libraries like 'node-ffi' to implement this functionality. Maybe someone will find it useful. It's WINDOWS OS ONLY

Features

  • Global keyboard event listener (keyDown / keyUp)
  • Window information & screenshots
  • Mouse movement, clicks, drag & drop
  • Keyboard emulation (keyPress, typeString)
  • OpenCV integration (template matching, blur, grayscale, histogram equalization, color manipulation, ROI, drawing)
  • Tesseract OCR text recognition
  • Screen capture
  • Mouse event listener
  • Prebuilt binaries (no Python or build tools required on Windows)
  • ESM + CommonJS support

Requirements

  • Windows 10 or later (x64)
  • Node.js >= 18 (prebuilts for recent versions via prebuildify)

Installation

npm install node-native-win-utils

Usage

import {
  KeyboardListener,
  KeyCodeHelper,
  KeyListener,
  getWindowData,
  captureWindow,
  captureWindowN,
  captureScreenToFile,
  mouseMove,
  mouseClick,
  mouseDrag,
  typeString,
  keyPress,
  textRecognition,
  OpenCV,
  startMouseListener,
  stopMouseListener,
} from "node-native-win-utils";

Keyboard

// Singleton listener
const listener = KeyboardListener.listener();
listener.on("keyDown", (data) => console.log("Down:", data.keyName));
listener.on("keyUp", (data) => console.log("Up:", data.keyName));

// Simulate key press
keyPress(KeyCodeHelper.A);           // once
keyPress(KeyCodeHelper.Enter, 2);    // twice

Mouse & Typing

mouseMove(500, 300);
mouseClick();                    // left click
mouseClick("right");
mouseClick("left", "down") // left button down
mouseClick("left", "up") // left button up
mouseDrag(100, 100, 800, 600, 50); // optional speed

typeString("Hello from Node!", 30); // 30ms delay per char

Window Operations

const data = getWindowData("Notepad");
console.log(data); // { width, height, x, y }

captureWindow("Notepad", "screenshot.png");
const buffer = captureWindowN("Notepad"); // Buffer

Screen Capture

await captureScreenToFile("full-screen.png");

Text Recognition (Tesseract OCR)

import path from "path";

const text = textRecognition(
  path.join(__dirname, "traineddata"), // path to .traineddata files
  "eng",
  path.join(__dirname, "image.png")
);
console.log(text);

OpenCV (image processing)

import { OpenCV } from "node-native-win-utils";

const img = new OpenCV("image.png"); // or ImageData { width, height, data: Uint8Array }

// Chainable methods
const processed = img
  .blur(5, 5)
  .bgrToGray()
  .equalizeHist()
  .darkenColor([240, 240, 240], [255, 255, 255], 0.5) // lower, upper, factor
  .drawRectangle([10, 10], [200, 100], [255, 0, 0], 3)
  .getRegion([50, 50, 300, 200]);

processed.imwrite("processed.png");

// Template matching
const match = img.matchTemplate(templateImage, /* method */, /* mask */);
console.log(match); // { minValue, maxValue, minLocation, maxLocation }

Mouse Event Listener

startMouseListener(({ x, y, type }) => {
  console.log(`${type} at ${x},${y}`); // move at 400 300
});

mouseClick("left"); // trigger event

// terminates a thread
stopMouseListener(); 

Building from source

npm install
npm run build

Requires:

Visual Studio Build Tools (C++).
Python 3

License

--

OpenCV License

MIT License

Made with ❤️ for Windows automation.
Issues / PRs welcome!

About

This package is a native addon for Node.js that allows you to perform various utility operations on Windows systems. It includes key event listeners, window data retrieval, window screenshot capture functionality, mouse movement, mouse click, mouse drag, and typing functionality, also I included precompiled libs of OpenCV(core, imgcodecs, imgproc)

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages