Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw keyboard capture with process.stdin doesn't work as expected. #50

Closed
john32b opened this issue Dec 17, 2015 · 8 comments
Closed

Raw keyboard capture with process.stdin doesn't work as expected. #50

john32b opened this issue Dec 17, 2015 · 8 comments

Comments

@john32b
Copy link

john32b commented Dec 17, 2015

I'm having problems capturing Raw keyboard input in a terminal on windows. This is driving me crazy, because I know that I had implemented this with older versions of nodejs (a year + ago)

Using the latest versions of NodeJS (currently using 4.2.2), capturing input seems buggy.. Unless I am missing something?

What I am running:
stdin = process.stdin;
stdin.on('data', function (data) {
    if (data == '\u0003') { process.exit(); }
    process.stdout.write('Captured Key : ' + data + "\n");
});
stdin.setEncoding('utf8');
stdin.setRawMode(true);
stdin.resume();
What I am expecting:

Immediately after running, the program should react to whatever key is pressed, and output:

Captured Key : T
Captured Key : E
Captured Key : S
. . . etc
What I am getting:

After running the program, the first keyboard input, acts as if it is NOT captured in Raw and it is captured and displayed on screen.

Then when I press the ENTER key, the text I just typed gets pushed to the handler function, AND THEN the program will accept further input in raw as expected.

Looks like as if the program requires an ENTER keystroke to initiate a proper raw mode input mode?

image
pic related: I typed TEST (ENTER). Then the program works as expected.

I am developing a custom TUI so this functionality is crucial for me.
Anyone knows what is this all about? I can't find anything. Also I don't want to use any external libraries.

Thanks !!

@Knighton910
Copy link
Contributor

@Knighton910
Copy link
Contributor

There is some minor depreciation going on here. 👎
screen shot 2015-12-17 at 12 29 09 pm

👍

But there pointing @ this
screen shot 2015-12-17 at 12 30 35 pm

@john32b
Copy link
Author

john32b commented Dec 17, 2015

Just tested the keypress package, same problem, It awaits an initial ENTER input, then it works normally.

I think the deprecated calls are for the TTY object, they suggest to call process.stdin. which is what I do ??

Perhaps it's on my end? But it's the same on 2 computers. Windows 10 and Windows 8.1.

I have a TUI lib that I was developing a year ago with node 0.10.0. But since I got back to it and decided to upgrade it to support the new nodes, that's where this problem came it.

It worked perfectly with older node versions, which is something to make be believe that this is a bug?

@john32b
Copy link
Author

john32b commented Dec 17, 2015

As a temporary solution I request an enter keystroke at the beginning of the program.
image

The user presses enter and then stdin raw captures the keys normally.

@Knighton910
Copy link
Contributor

Yeah, the temporary solution is good, but It's a weird problem. Well alright then let me know if you wish further help.

@john32b
Copy link
Author

john32b commented Dec 17, 2015

Will do, thanks! 😺

@ChiriVulpes
Copy link

AFAIK, this is still an issue, should it be reopened as a bug on nodejs/node? Having troubles getting it to work correctly on Node 5.7.1, Windows 10.

@ChiriVulpes
Copy link

If anyone is still watching this issue, a fix is incoming: libuv/libuv#866

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants