linux-events 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # linux-events
2
+ A small package for listening to evdev (/dev/input/eventX) device streams on Linux
3
+
4
+ ## Usage
5
+ ### listDevices([options])
6
+ Lists devices in `/dev/input`.
7
+ - **options:** An object used to provide optional arguments.
8
+ - **info:** Automatically fetches the device name from `/sys/class/input`.
9
+
10
+ Example:
11
+ ```js
12
+ import { listDevices } from '';
13
+
14
+ console.log(listDevices()); // Prints: [ { device: 'event0' }]
15
+ console.log(listDevices({ info: true })); // Prints: [ { device: 'event0', name: 'Mouse' }]
16
+ ```
17
+
18
+ ### Class: DeviceListener
19
+ Listens to a device's input stream
20
+ - **constructor(device, [...args]):**
21
+ - **device:** The device to listen to (e.g. `event0`)
22
+ - **args:** Args to pass to the EventEmitter constructor
23
+ - **stop():** Destroys the read stream and stops listening for input.
24
+ - events
25
+ - **data:** Emitted when input is received from the device.
26
+ - **input:** An object version of the `input_event` struct (see https://docs.kernel.org/input/input.html#event-interface).
27
+ - **error:** Emitted when an 'error' event is received from the read stream.
28
+ - **error**
29
+ - **close:** Emitted when a 'close' event is received from the read stream.
30
+ - **end:** Emitted after `stop()` or when an 'end' event is received from the read stream.
31
+
32
+ Example:
33
+ ```js
34
+ import { DeviceListener } from '';
35
+
36
+ let listener = new DeviceListener('event0');
37
+ listener.on('data', input => console.log(input));
38
+ listener.on('error', error => console.log('Error reading device input:', error));
39
+ console.log('Listening for input...');
40
+ // ...
41
+ listener.stop();
42
+ console.log('Stopped listening for input.');
43
+ ```
44
+
45
+ An input event for relative mouse movement would look something like this:
46
+ ```js
47
+ {
48
+ tv_sec: 1783887711n,
49
+ tv_usec: 338192n,
50
+ type: 'REL',
51
+ code: 'REL_X',
52
+ value: 1
53
+ }
54
+ ```
55
+ See https://docs.kernel.org/input/event-codes.html#input-event-codes for all event types.