Giter Club home page Giter Club logo

node-hid-stream's Introduction

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

node-hid-stream's People

Contributors

agirorn avatar ceremcem avatar cominch avatar dependabot[bot] avatar iamblue avatar kubat avatar openhoat avatar robrichard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

node-hid-stream's Issues

I can install node-hid but not this

..\src\HID.cc(67): warning C4290: C++ exception specification ignored except to indicate a function is not __declspe
c(nothrow) [C:\Users\Xela\Desktop\hid-stream-test\node_modules\node-hid-stream\node_modules\node-hid\build\HID.vcxproj]
..\src\HID.cc(70): warning C4290: C++ exception specification ignored except to indicate a function is not __declspe
c(nothrow) [C:\Users\Xela\Desktop\hid-stream-test\node_modules\node-hid-stream\node_modules\node-hid\build\HID.vcxproj]
..\src\HID.cc(152): warning C4290: C++ exception specification ignored except to indicate a function is not __declsp
ec(nothrow) [C:\Users\Xela\Desktop\hid-stream-test\node_modules\node-hid-stream\node_modules\node-hid\build\HID.vcxproj]
..\src\HID.cc(163): warning C4290: C++ exception specification ignored except to indicate a function is not __declsp
ec(nothrow) [C:\Users\Xela\Desktop\hid-stream-test\node_modules\node-hid-stream\node_modules\node-hid\build\HID.vcxproj]

..\src\HID.cc(207): error C2661: 'v8::Function::NewInstance': no overloaded function takes 2 arguments [C:\Users\Xela\Desktop\hid-stream-test\node_modules\node-hid-stream\node_modules\node-hid\build\HID.vcxproj]

..\src\HID.cc(231): warning C4996: 'Nan::Callback::Call': was declared deprecated [C:\Users\Xela\Desktop\hid-stream-test
\node_modules\node-hid-stream\node_modules\node-hid\build\HID.vcxproj]
  C:\Users\Xela\Desktop\hid-stream-test\node_modules\nan\nan.h(1618): note: see declaration of 'Nan::Callback::Call'
..\src\HID.cc(398): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc [
C:\Users\Xela\Desktop\hid-stream-test\node_modules\node-hid-stream\node_modules\node-hid\build\HID.vcxproj]
..\src\HID.cc(409): warning C4996: 'v8::String::Value::Value': was declared deprecated [C:\Users\Xela\Desktop\hid-stream-test\node_modules\node-hid-stream\node_modules\node-hid\build\HID.vcxproj]
  C:\Users\Xela\Desktop\hid-stream-test\.node-gyp\10.1.0\include\node\v8.h(2846): note: see declaration of 'v8::String::Value::Value'
..\src\HID.cc(488): warning C4244: 'argument': conversion from 'wchar_t' to 'char', possible loss of data [C:\Users\Xela\Desktop\hid-stream-test\node_modules\node-hid-stream\node_modules\node-hid\build\HID.vcxproj]
gyp ERR!
build error

..\src\HID.cc(207): error C2661: 'v8::Function::NewInstance': no overloaded function takes 2 arguments [C:\Users\Xela\Desktop\hid-stream-test\node_modules\node-hid-stream\node_modules\node-hid\build\HID.vcxproj]

This is the error, what do I do?

cannot open device

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

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

I am using the basic code only to read data from a scanner on windows 10 but i get this error :

C:\Users\Balkan_Med1\Desktop\scanner2\node_modules\node-hid-stream\node_modules\node-hid\nodehid.js:24
this._raw = new (Function.prototype.bind.apply(binding.HID,
^

Error: cannot open device with vendor id 0xffff and product id 0x35
at new HID (C:\Users\Balkan_Med1\Desktop\scanner2\node_modules\node-hid-stream\node_modules\node-hid\nodehid.js:24:17)
at newHidDevice (C:\Users\Balkan_Med1\Desktop\scanner2\node_modules\node-hid-stream\lib\hidstream.js:55:10)
at new Hidstream (C:\Users\Balkan_Med1\Desktop\scanner2\node_modules\node-hid-stream\lib\hidstream.js:21:19)
at new KeyboardBase (C:\Users\Balkan_Med1\Desktop\scanner2\node_modules\node-hid-stream\lib\keyboard-base.js:9:19)
at new Keyboard (C:\Users\Balkan_Med1\Desktop\scanner2\node_modules\node-hid-stream\lib\keyboard.js:9:5)
at Object. (C:\Users\Balkan_Med1\Desktop\scanner2\index.js:3:20)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)

QR reader with hidrwa0 and hidraw1

Is there a way to force the library to read from hidraw1 ?
I'm using the library in a RPi4, node-red 2.05, with an Aibecy QR reader and it's working right, this device appears, in /dev, like hidraw0. The problem arise when I connect an MP2600 QR reader (has no brand on the box) in the place of the Aibecy. This new device shows two hidraws on the /dev. The hidraw0 and hidraw1. As per what I observed with cat /dev/hidraw1, it communicates through hidraw1. The hidraw0 is always in silence. I'm not able to read any data in node red. it seems like the library (node-red-stream) wait for data coming from hidraw0. This is why my question in line 1.
Appreciate any comment or work around to resolve the issue
kind regards.
zapicoj

Installing node-hid-stream: too few arguments to function call, expected 3, have 2

Error while installing node-hid:

gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! ../src/HID.cc:612:31: error: too few arguments to function call, expected 3, have 2
npm ERR! node::AtExit(deinitialize, 0);
npm ERR! ~~~~~~~~~~~~ ^
npm ERR! /Users/milosmihic/Library/Caches/node-gyp/16.13.0/include/node/node.h:913:18: note: 'AtExit' declared here
npm ERR! NODE_EXTERN void AtExit(Environment* env,
npm ERR! ^
npm ERR! 1 error generated.
npm ERR! make: *** [Release/obj.target/HID/src/HID.o] Error 1

node version: 16.13.0
npm version: 8.1.0
os: macOS Monterey v12.0.1

Data limit from a barcode seems to be 64

When I try to scan an AZTEC 2D code, I received at least 4 consecutive datas. Is it a mis-configuration of the scanner or just that the data is too long that it should be splited into 4 parts of 3 64characters and then the rest?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.