Skip to content

Instantly share code, notes, and snippets.

@newvertex
Created September 17, 2016 10:24
Show Gist options
  • Save newvertex/d78b9c6050d6a8f830809e6e528d5e96 to your computer and use it in GitHub Desktop.
Save newvertex/d78b9c6050d6a8f830809e6e528d5e96 to your computer and use it in GitHub Desktop.
Example: Detect keypress event in Node.js console app
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();
});
@jgan42
Copy link

jgan42 commented Aug 5, 2022

👍

@kasterra
Copy link

kasterra commented Aug 9, 2022

👍

@torchiaf
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment