https://github.com/heedrox/readkey
A simple node key listener to read keys pressed on keyboard (based on a config object)
https://github.com/heedrox/readkey
Last synced: about 2 months ago
JSON representation
A simple node key listener to read keys pressed on keyboard (based on a config object)
- Host: GitHub
- URL: https://github.com/heedrox/readkey
- Owner: heedrox
- Created: 2018-12-30T10:21:52.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-30T10:25:33.000Z (over 7 years ago)
- Last Synced: 2025-10-22T04:28:40.142Z (8 months ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# readkey
A simple node key listener to read keys pressed on keyboard.
# Usage
Create a config object with:
- fn: the function that evaluates if the key has been pressed.
- command: the command executed if fn() returns true
Send it to readkey();
```
const readkey = require('readkey');
const keyCommands = [
{ fn: (str, key) => str === 'p', command: () => console.log('p was pressed') },
{ fn: (str, key) => key.ctrl && key.name === 'c', command: () => process.exit() },
{ fn: (str, key) => key.name === 'q', command: () => process.exit() },
];
readkey(keyCommands);
```