I am new to NodeJS. I am working on a Node.js application where I need to disable keyboard input from being displayed on the terminal screen. However, I still want to detect keypress events. I want to allow the user to press keys (like spacebar) without those keys being printed on the screen, but I need to capture the keypress events for other functionalities.
I have a function spell that writes text character by character to the terminal, which can skip to the end when the spacebar is pressed and needs the spacebar to be pressed again to end.
process.stdin.on('keypress', (str, key) => { if (key.name) { KHGO[key.name] = true; setTimeout(() => { KHGO[key.name] = false; } }, 100); }});async function spell(string, ms){ let skipped = false; const characterArray = string.split(""); //Write character by character if space is pressed write everything for (let i = 0; i < characterArray.length; i++) { process.stdout.write(string[i]); if (!skipped) await sleep(ms); if (KHGO.space) { skipped = true } KHGO.space = false; } //wait until space is pressed to continue while(true){ if(KHGO.space){ KHGO.space=false; return; } await sleep(1); }}
But when you skip, the space is seen in the text, plus any other keys you press are also visible. I also don't want to permanently disable keyboard writing, I want some kind of functions like disableKeyboard()
and enableKeyboard()