You are browsing as a guest. Sign up (or log in) to start making projects!

5h 1m 35s logged

Just published the evdevlib package on npm!

Usage

listDevices([options])

Lists available character devices.

  • options: An object used to provide optional arguments.
    • info: Automatically fetches the device name from /sys/class/input.
    • path: Which directory to scan for devices (default: /dev/input).

Example:

import { listDevices } from 'evdevlib';

console.log(listDevices()); // Prints: [ { path: '/dev/input/event0' }]
console.log(listDevices({ info: true })); // Prints: [ { path: '/dev/input/event0', name: 'Mouse' }]

Class: DeviceListener

Listens to a device’s input stream

  • constructor(path, […args]):
    • path: The path of the interface to listen to (e.g. /dev/input/event0)
    • args: Args to pass to the EventEmitter constructor
  • stop(): Destroys the read stream and stops listening for input.
  • events
    • data: Emitted when input is received from the device.
    • error: Emitted when an ‘error’ event is received from the read stream.
      • error
    • close: Emitted when a ‘close’ event is received from the read stream.
    • end: Emitted after stop() or when an ‘end’ event is received from the read stream.

Example:

import { DeviceListener } from 'evdevlib';

let listener = new DeviceListener('/dev/input/event0');
listener.on('data', input => console.log(input));
listener.on('error', error => console.log('Error reading device input:', error));
console.log('Listening for input...');
// ...
listener.stop();
console.log('Stopped listening for input.');

An input event for relative mouse movement would look something like this:

{
    tv_sec: 1783887711n,
    tv_usec: 338192n,
    type: 'REL',
    code: 'REL_X',
    value: 1
}

See https://docs.kernel.org/input/event-codes.html#input-event-codes for all event types.

0
2

Comments 0

No comments yet. Be the first!