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).
-
info: Automatically fetches the device name from
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
-
path: The path of the interface to listen to (e.g.
- stop(): Destroys the read stream and stops listening for input.
- events
-
data: Emitted when input is received from the device.
-
input: An object version of the
input_eventstruct (see https://docs.kernel.org/input/input.html#event-interface).
-
input: An object version of the
-
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.
-
data: Emitted when input is received from the device.
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.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.