Created
September 17, 2016 10:24
Example: Detect keypress event in Node.js console app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var readline = require('readline'); | |
readline.emitKeypressEvents(process.stdin); | |
if (process.stdin.isTTY) | |
process.stdin.setRawMode(true); | |
process.stdin.on('keypress', (chunk, key) => { | |
if (key && key.name == 'q') | |
process.exit(); | |
}); |
🐐
Thank you!
Thanks for this. Is there a standard way to detect a keyrelease event or do we need to rely on some timeout logic which tracks inactivity?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍