Skip to content

Instantly share code, notes, and snippets.

@h2rd
Created December 3, 2012 22:32
Show Gist options
  • Select an option

  • Save h2rd/4198748 to your computer and use it in GitHub Desktop.

Select an option

Save h2rd/4198748 to your computer and use it in GitHub Desktop.
console get key
var keypress = require('keypress')
, tty = require('tty');
// make `process.stdin` begin emitting "keypress" events
keypress(process.stdin);
// listen for the "keypress" event
process.stdin.on('keypress', function (ch, key) {
console.log('got "keypress"', key.name);
if (key && key.ctrl && key.name == 'c') {
process.stdin.pause();
}
});
if (typeof process.stdin.setRawMode == 'function') {
process.stdin.setRawMode(true);
} else {
tty.setRawMode(true);
}
process.stdin.resume();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment