【发布时间】:2021-07-23 04:16:13
【问题描述】:
我正在使用 Nodejs 的 readline 模块,我想要做的是当用户输入一个字母时。他们输入的键我想立即返回该键(字母),就像按下回车键一样,但仍然是他们按下的键(字母)。
在下面的代码中,我有提示要求用户输入 w、a、s 或 d 所以我希望这 4 个键在单击时立即返回,如果他们输入任何其他键,终端会忽略它根本不显示我该怎么做?
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
/// the function is below
function userInput(input) {
input = readline.question('Please move\n (w for up)\n (a for left)\n (s for down)\n (d for right)',
theMove => {
console.log(`Nice move ${theMove}!`);
readline.close();
});
userInput();
【问题讨论】:
标签: javascript node.js module node-modules readline