Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hid-input

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hid-input

Node.js binding for reading text inputs on Linux, such as barcode scanners

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

node-hid-input

license issues stars commits

Node.js binding for reading text inputs on Linux, such as barcode scanners.

Why another...?

Features:

  • First class TypeScript support
  • Node-API addon for better parsing of input_event
  • Supports exclusive (EVIOCGRAB) open
  • Mocking interface for better unit testing, even on platforms other than Linux

Installation

npm install --save hid-input

Build from source

npm install --save hid-input --build-from-source

Additional build dependencies are required on different platforms:

Debian/Ubuntu
sudo apt install -y build-essential cmake ninja-build
macOS
brew install cmake ninja

Usage

import { createInput, listInputs } from 'hid-input';

const inputs = await listInputs();
console.log(inputs);

const reader = createInput(inputs[0].path);
reader.once('open', ()=>{
  console.log('device opened');
});
reader.on('data', (input) => {
  console.log(`- scanned: ${input}`);
});

APIs

listInputs()

  • Returns: Promise<InputDevice[]>
    • path - string Path to the device
    • name - string Human readable name of the deivce

List HID input devices available on this machine.

createInput(path[, options])

  • path - string
  • options - Object
    • exclusive - boolean Whether to prevent the device from being opened by other processes before getting closed
  • Returns: HidInputStream

Opens an input stream of device path. Available devices along with paths can be retrieved with listInputs().

createMockInput(path)

  • path - string
  • Returns: HidInputStream

Opens a mocking stream by listening on a newly created UNIX domain socket path.

After the stream is open, you can emulate inputs with nc -U <path>.

Class: HidInputStream

  • Extends fs.Readable

A readable stream in Object mode.

Event: open
Event: close
Event: data
  • input - string Input read from the device
close()

Close the stream and release any underlying resources.

License

MIT License

Keywords

FAQs

Package last updated on 12 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc