Skip to content

Instantly share code, notes, and snippets.

@natchiketa
Created October 2, 2015 20:25
Show Gist options
  • Save natchiketa/9c44899639c2ea55e5ed to your computer and use it in GitHub Desktop.
Save natchiketa/9c44899639c2ea55e5ed to your computer and use it in GitHub Desktop.
Using the Node keypress package

After installing keypress (npm install keypress), running this in the Node REPL will show you what the names an codes are for different keypresses.

var keypress = require('keypress');

// 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);
  if (key && key.ctrl && key.name == 'c') {
    process.stdin.pause();
  }
});

process.stdin.setRawMode(true);
process.stdin.resume();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment