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-hid-stream

v1.1.0

Published

Stream data from HID device in Node.js

Downloads

80

Readme

npm version Build Status

NODE HID STREAM

Stream data from HID device in Node.js

Wraps node-hid in a node.js Stream.

HID devices, specifically, keyboard-like devices.

Available Streams are:

  • Hidstream: Stream data from node-hid.
  • Keyboard: Stream for keyboard-like devices.
  • KeyboardCharacters: for keyboard-like devices that streams characters.
  • KeyboardLines: for keyboard-like devices stream lines split on ENTER. Can be used to read from barcode scanners.

keyboard-like = (keyboards or barcode scanners)

Installation

You have to make sure you can install node-hid before you install this module.

npm install node-hid-stream

Usage

Hidstream

var Hidstream = require('node-hid-stream').Hidstream;
var hidstream = new Hidstream({ vendorId: 3233, productId: 3233 });

hidstream.on("data", function(data) {
  console.log(data); // Raw buffer from HDI device.
});

KeyboardLines

var KeyboardLines = require('node-hid-stream').KeyboardLines;
var lines = new KeyboardLines({ vendorId: 3233, productId: 3233 });

lines.on("data", function(data) {
  // The user has pressed w, a, s & d, ENTER (simultaneously (why? I don't know))
  console.log(data); //  "wasd"
});

KeyboardCharacters

var KeyboardCharacters = require('node-hid-stream').KeyboardCharacters;
var characters = new KeyboardCharacters({ vendorId: 3233, productId: 3233 });

characters.on("data", function(data) {
  // The user has pressed w, a, s & d (simultaneously (why? I don't know))
  console.log(data); //  "wasd"
});

Keyboard

var Keyboard = require('node-hid-stream').Keyboard;
var keyboard = new Keyboard({ vendorId: 3233, productId: 3233 });

keyboard.on("data", function(data) {
  console.log(data); // easily consumed data format!
});

Sample Data Event from Keyboard stream:

The user has pressed Ctrl + Alt + Del

{  // HidKeyboardPacket
  modifiers: {
    leftShift: false,
    leftControl: true,
    leftAlt: true,
    leftMeta: false,
    rightCtrl: false,
    rightShift: false,
    rightAlt: false,
    rightMeta: false
  },
  keyCodes: [ 76 ],
  keyChars: [],
  errorStatus: false
}

The user has pressed w, a, s & d (simultaneously (why? I don't know))

{  // HidKeyboardPacket
  modifiers: {
    leftShift: false,
    leftControl: false,
    leftAlt: false,
    leftMeta: false,
    rightCtrl: false,
    rightShift: false,
    rightAlt: false,
    rightMeta: false
  },
  keyCodes: [ 26, 4, 22, 7 ],
  charCodes: [ 'w', 'a', 's', 'd' ],
  errorStatus: false
}

HidKeyboardPacket

HidKeyboardPacket has additional convenience methods

  • shift() returns true if left or right shift key is pressed.
  • control() returns true if left or right control key is pressed.
  • alt() returns true if left or right alt key is pressed.
  • meta() returns true if left or right meta key is pressed.
  • mod() returns true returns true if any of the modifier keys is pressed.
  • empty() returns true if no key or modifier is pressed.

Contributions

This is based on hidstream from Emily Rose

Significant refactor contributed by @kubat