Skip to content

A windows library for intercepting and controlling keyboards and mouses with multiple devices support.

License

Notifications You must be signed in to change notification settings

Rami-Sabbagh/node-interception

Repository files navigation

node-interception

GitHub NPM License Documentation Dependabot

A windows library for intercepting and controlling keyboards and mouses with multiple devices support.

The package provides Node.js bindings for the original Interception library by Oblitum, and supports it with a wrapper and TypeScript definitions.

Example

// Increase the process priority to prevent input lagging.
import * as os from 'os';
os.setPriority(os.constants.priority.PRIORITY_HIGH);

import { Interception, FilterKeyState, FilterMouseState } from 'node-interception';
const interception = new Interception();

// Display the list of available devices.
console.log('Devices:', interception.getDevices().map(device => `${device}`));

// Enable the capturing of all strokes.
interception.setFilter('keyboard', FilterKeyState.ALL);
interception.setFilter('mouse', FilterMouseState.ALL);

const SCANCODE_ESC = 0x01;

async function listen() {
    console.info('Press any key or move the mouse to generate strokes.');
    console.info('Press ESC to exit and restore back control.');

    while (true) {
        const device = await interception.wait();
        const stroke = device?.receive();

        if (!device || !stroke || (stroke?.type === 'keyboard' && stroke.code === SCANCODE_ESC)) break;

        console.log(`${device}`, stroke);
    }

    interception.destroy();
}

// Start listening for keyboard and mouse strokes.
listen().catch(console.error);

Features

  • Contains prebuilt binaries for 32-bit (ia32) and 64-bit (x64) Windows machines.
  • Written using N-API and node-addon-api so it should work with different node versions and electron without rebuilding.
  • Written in TypeScript to provide enhanced IDE support.
  • Allows working with each mouse and keyboard as independent devices, so different logic can be used for each keyboard/mouse.
  • Allows blocking or modifying the devices strokes.

Interception use cases

As the original library author (Oblitum) written:

Interception has been used around the world in cases I couldn't imagine when I first created it:

  • Helping people with accessibility limitations, tailoring systems according to their limitations.
  • By companies in aviation training, to connect many devices at once and customizing each one.
  • By companies providing SCADA (supervisory control and data acquisition) solutions.
  • In game applications like BOTs and control customization.
  • To construct an emacs mode of the system.
  • To customize supermarket cashier's systems.
  • In doctoral thesis about typing pattern recognition for security applications.
  • Home theater automation.
  • ...

Documentation

The API documentation is generated using TypeDoc and available on GitHub Pages.

When in need for more help

You can create an issue here or email me on [email protected].

Please mind that I made this project in my free time for nothing in return. And that it usually takes up to 5 days for me to reply back (possibly more on some occasions).

Installation

Installing the package

yarn add node-interception
rem -- or using npm
npm install node-interception

Installing the driver

Using a command prompt with Administrative Privileges:

npx node-interception /install

You can uninstall it later using /uninstall instead.

You'll need to restart for the driver installation to be complete.

License

The binding and wrapper are licensed under LGPL-3.0-or-later, check the LICENSE file.

The original Interception library is licensed under LGPL-3.0 too for un-commercial usage and has a seperate license for commercial usage, check it in it's repository.

The package and repository of this module contains a redistribution of the interception library as that's permitted by the LGPL-3.0 license, please create an issue if that's incorrect.

Credits

  • Oblitum for creating the original interception library.
  • Rami Sabbagh for writing the binding and wrapper.