Created
December 3, 2012 22:32
-
-
Save h2rd/4198748 to your computer and use it in GitHub Desktop.
console get key
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 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