可以在运行的nodejs脚本中监听传入的击键吗?
// stdin_test.js
var stdin = process.openStdin();
stdin.on('data', function(chunk) { console.log("Got chunk: " + chunk); });
运行这个,我得到:
$ node stdin_test.js
<-- type '1'
<-- type '2'
<-- hit enter
Got chunk: 12
我想看到的是:
$ node stdin_test.js
<-- type '1' (without hitting enter yet)
Got chunk: 1
我在找一个相当于getc
in ruby的nodejs
这可能吗?