Created
September 17, 2016 10:24
-
-
Save newvertex/d78b9c6050d6a8f830809e6e528d5e96 to your computer and use it in GitHub Desktop.
Example: Detect keypress event in Node.js console app
This file contains 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(); | |
}); |
Really nice! Thanks man!
π
π
π
π
π
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
Thank you!