https://github.com/pfirpfel/node-exclusive-keyboard
Keylogger for NodeJS and Linux that grabs the input device exclusively using ioctl EVIOCGRAB.
https://github.com/pfirpfel/node-exclusive-keyboard
eviocgrab ioctl keyboard keylogger linux-devices nodejs
Last synced: about 1 month ago
JSON representation
Keylogger for NodeJS and Linux that grabs the input device exclusively using ioctl EVIOCGRAB.
- Host: GitHub
- URL: https://github.com/pfirpfel/node-exclusive-keyboard
- Owner: pfirpfel
- License: mit
- Created: 2019-07-22T19:49:58.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T08:02:34.000Z (over 2 years ago)
- Last Synced: 2025-01-02T05:52:49.329Z (5 months ago)
- Topics: eviocgrab, ioctl, keyboard, keylogger, linux-devices, nodejs
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 12
- Watchers: 3
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-exclusive-keyboard
Keylogger for NodeJS and Linux that grabs the input device exclusively.Useful for capturing USB input devices that act like keyboards, so that their inputs do no pollute other processes like terminals.
Based on [node-keylogger](https://github.com/taosx/node-keylogger/) and [node-ioctl](https://github.com/santigimeno/node-ioctl).
## Installation
```bash
npm install --save exclusive-keyboard
```## Usage
Set access control right to device for user `username`:
```bash
sudo setfacl -m u:username:r /dev/input/by-id/usb-Logitech_Logitech_USB_Keyboard-event-kbd
``````js
const ExclusiveKeyboard = require('exclusive-keyboard');const keyboard = new ExclusiveKeyboard('by-id/usb-Logitech_Logitech_USB_Keyboard-event-kbd', true);
keyboard.on('keyup', console.log);
keyboard.on('keydown', console.log);
keyboard.on('keypress', console.log);
keyboard.on('close', console.log);
keyboard.on('error', console.error);
```## API
### `new ExclusiveKeyboard(dev, exclusive)`
* `dev` (string): Device name (part after '/dev/input/'). Example: 'event0' would use '/dev/input/event0'
* `exclusive` (boolean): If true, grab device exclusively using ioctl EVIOCGRAB (default: true)### `close()`
Releases the grabbed device and closes the file descriptor. Emits 'close' event when done.### ExclusiveKeyboard.Keys
Mapping of key codes to key ids, see `keycodes.js`.### Event `keyup(event)`
Example event:
```js
{
timeS: 39234,
timeMS: 3812,
keyCode: 71,
keyId: 'KEY_KP7',
type: 'keyup',
dev: 'by-id/usb-SEM_Trust_Numpad-event-kbd'
}
```### Event `keypress(event)`
Example event:
```js
{
timeS: 39234,
timeMS: 3812,
keyCode: 71,
keyId: 'KEY_KP7',
type: 'keypress',
dev: 'by-id/usb-SEM_Trust_Numpad-event-kbd'
}
```### Event `keydown(event)`
```js
{
timeS: 39234,
timeMS: 3812,
keyCode: 71,
keyId: 'KEY_KP7',
type: 'keydown',
dev: 'by-id/usb-SEM_Trust_Numpad-event-kbd'
}
```### Event `error(error)`
### Event `close()`
## Contributors
Thank you to the following contributors:* [Janek Thomaschewski](https://github.com/jthomaschewski)