What you might be looking for is the rs.setRawMode(mode)
for the native TTY
modules. Originally in Node v0.8.x, there was a undocumented keypress
event for process.stdin
that would emit when it was a TTY. It was then altered to only fire when being used with readline
, so I would suggest using that.
The functionality is still accessible by a module called keypress
. It was directly taken from Node source, and is used like so (taken from documentation):
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();
It's also been altered to support a mousepress
event that you will also find on the GitHub page.