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 = Hidstream;var hidstream = vendorId: 3233 productId: 3233 ; hidstream;
KeyboardLines
var KeyboardLines = KeyboardLines;var lines = vendorId: 3233 productId: 3233 ; lines;
KeyboardCharacters
var KeyboardCharacters = KeyboardCharacters;var characters = vendorId: 3233 productId: 3233 ; characters;
Keyboard
var Keyboard = Keyboard;var keyboard = vendorId: 3233 productId: 3233 ; keyboard;
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