I have a simple Node CLI app that runs a long-running process, in this case a Gradle in watch mode.
I need to have some user control so I added a fairly standard setup for reading the keys like this:
process.stdin.setRawMode(true);
process.stdin.resume();
process.stdin.on('data', (key: Buffer) => {
console.log('Key pressed:', key.toString());
if (key.toString() === '\u0003') {
process.exit();
}
});
The issue here is that in this scenario only every other key is actually read, starting second press, the rest is missing.
This only happens when the child process is started, otherwise all the keys are read normally. What is the cause of this? How can this be solved?