Read command line key presses from process.stdin. Based on TooTallNate/keypress
.
npm install @derhuerst/cli-on-key
listen
will switch the stream to raw mode, stopListening
will revert to the previous value.
const listen = require('cli-on-key')
const stopListening = listen(process.stdin, (key) => {
if (key.ctrl && key.name === 'c') {
stopListening() // stop on Ctrl + C
} else console.log(key)
})
If you have a question or have difficulties using cli-on-key
, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to the issues page.