I saw some code snippet like below:
process.stdin.on('keypress', function(c, key){
if (key && 'enter' == key.name) {
But sadly I couldn't find anything about how to use keypress
event in node
's docs. Obviously it's different from keypress
event in browsers. Moreover there is nothing introducing what key
object is, so I don't know how to use key.xxx
or key.name == xxx
to detect which key user is pressing.
What do I miss? There must be somewhere I can found how to use node
...
The node documentation seems quite lacking in that regard like you mentioned.
The only reference I found was when going through the source for the 'readline'-module:
function emitKey(stream, s) {
var ch,
key = {
name: undefined,
ctrl: false,
meta: false,
shift: false
},
and so on, basically the name, if ctrl is pressed, if shift is pressed, and some meta.
There's no doubt the docs needs some work :)