var readline = require('readline');
readline.emitKeypressEvents(process.stdin);
if (process.stdin.isTTY)
process.stdin.setRawMode(true);
console.log('press q to exit, or any key to print log');
process.stdin.on('keypress', (chunk, key) => {
if (key && key.name == 'q'){
process.exit();
}
console.log({key});
});
3条答案
按热度按时间prdp8dxp1#
只需使用iohook npm module。这是一个示例:
但这道题与这道题重复
yvfmudvl2#
从这里;
56lgkhnf3#
iohook仅支持节点js v8.x - v15.x
读取行支持当前节点js v19.x
尝试使用以下命令安装readline:npm i读取行