npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-direct-input

v1.0.0

Published

It detects events for keyboard keys and gaming device buttons (not axes) even when the focus is not on the program, and it does not block events for other open applications.

Downloads

5

Readme

Node Direct Input

It detects events for keyboard keys and gaming device buttons (not axes) even when the focus is not on the program, and it does not block events for other open applications.

This module is designed to complement games with external applications in which you need to know when a key or button on the keyboard or any gaming device that is connected to the computer has been pressed. If you need more functionalities, you have a base made and knowing a little C# and C++ you are free to adapt it to your needs if, for example, you need to also obtain the axes of the game devices or mouse events among other things.

Install

npm i node-direct-input

Build

The package is compiled for the node.js version 12.16.0, it is possible to make reconstructions for other node versions, but a correct operation of the versions prior to 12 is not guaranteed. The module makes use of Worker Threads which is Available only from version 11.7.0 of node.js and other plugins that are only available in the newer versions of nodejs.

To build the node package, just run the following command after installing the development dependencies:

$ npm run rebuild

If you want to use the package in a different execution environment such as NWJS or Electron, there are two ways to compile the module. The first is to edit the package.json and modify the following lines to suit your version of NWJS or Electron:

"scripts": {
    "test": "node test/test.js",
    "clean": "cmake-js clean",
    "build": "cmake-js build -G \"Visual Studio 15 2017 Win64\"",
    "rebuild": "cmake-js rebuild -G \"Visual Studio 15 2017 Win64\"",
    "build-nw": "cmake-js build --runtime=nw --runtime-version=<<YOUR-NW-VERSIONI>> --arch=x64 -G \"Visual Studio 15 2017 Win64\"",
    "rebuild-nw": "cmake-js rebuild --runtime=nw --runtime-version=<<YOUR-NW-VERSIONI>> --arch=x64 -G \"Visual Studio 15 2017 Win64\"",
    "build-electron": "cmake-js build --runtime=electron --runtime-version=<<YOUR-ELECTRON-VERSIONI>> --arch=x64 -G \"Visual Studio 15 2017 Win64\"",
    "rebuild-electron": "cmake-js build --runtime=electron --runtime-version=<<YOUR-ELECTRON-VERSIONI>> --arch=x64 -G \"Visual Studio 15 2017 Win64\""
}

Replace the text <<YOUR-XX-VERSION>> with the NWJS or electron version in which the module will be compiled and then execute the corresponding script depending on where you are compiling the module

# For NWJS
$ npm run rebuild-nw

# For Electrón
$ npm run rebuild-electron

You can also do a more specific manual compilation by following the instructions in cmake-js.

Use

const nodeDirectInput = require("node-direct-input");
const di = new nodeDirectInput();

Listen key or games device buttons events

// Start events listen
di.listen();

// Event dispatch when a new device is connected or disconnected
di.on("ndi:devices", (devices) => {
  console.log(devices);
});

// Event dispatch when key or button presseds change
di.on("ndi:keysPressed", (keysPressed) => {
  console.log(keysPressed);
});

Stop listen

di.stop();

Request connected devices

Is not necesary be listening

const devices = di.getDevicesConnected();
console.log(devices);