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

process.stdin keypress event returns ctrl: false in a [control + [backspace] event #2890

Closed
dthree opened this issue Sep 15, 2015 · 8 comments
Labels
process Issues and PRs related to the process subsystem. question Issues that look for answers.

Comments

@dthree
Copy link

dthree commented Sep 15, 2015

When logging a keypress event, the [control] key generally provides a { ... ctrl: true } in the return keypress data returned on the event. However, peculiarly, when [control + [backspace] event is fired, ctrl is returned as false.

Steps to reproduce:

var rl = require('readline');

var i = rl.createInterface(process.stdin, process.stdout, null);
i.question("What do you think of node.js?", function(answer) {
  console.log("Thank you for your valuable feedback.");
  i.close();
  process.stdin.destroy();
});

process.stdin.on('keypress', function(key, data){
  console.log(data);
});

/*
  { sequence: ',
  name: 'backspace',
  ctrl: false,        < -- should be true
  meta: false,
  shift: false }
*/

This was verified to be a situation in v4.0.0.

@dthree dthree changed the title process.stdin keypress event omits ctrl: true in a [control + [backspace] event process.stdin keypress event returns ctrl: false in a [control + [backspace] event Sep 15, 2015
@mscdex mscdex added the process Issues and PRs related to the process subsystem. label Sep 15, 2015
@Fishrock123
Copy link
Contributor

Afaik, you'll need to put the readline into terminal mode for this? https://github.com/nodejs/node/blob/master/lib/readline.js#L124

I don't think process.stdin itself does this. Weirdly enough, Readline emits events on it's input stream.

@Fishrock123 Fishrock123 added the question Issues that look for answers. label Sep 16, 2015
@dthree
Copy link
Author

dthree commented Sep 16, 2015

Ah. Got it. Tried terminal mode as such, to the same result:

var i = rl.createInterface({
  input: process.stdin,
  output: process.stdout, 
  terminal: true 
});

It's literally the control + backspace combination. For example, control + d or any other character returns the correct object, terminal mode or not. Can't find where in readline the event object is assembled, however.

Any ideas?

@dthree
Copy link
Author

dthree commented Sep 16, 2015

Looks like the emitKeys function might have something funky:

https://github.com/nodejs/node/blob/master/lib/readline.js#L984

@dthree
Copy link
Author

dthree commented Sep 16, 2015

Looks like control isn't computed for backspace

} else if (ch === '[') {
...
// Parse the key modifier
key.ctrl = !!(modifier & 4);
...
} else if (ch === '\b' || ch === '\x7f') {
// backspace or ctrl+h
key.name = 'backspace';
key.meta = escaped;

It looks like the key modifier methods are just not checked for the backspace character, only the main keys (starting with [ or something).

Any idea why?

@SBoudrias
Copy link

@Fishrock123 the terminal option is defaulting to the isTTY check of the output stream. In this case, it looks like @dthree would already be in that mode no?

@jasnell
Copy link
Member

jasnell commented Mar 22, 2016

ping @Fishrock123 ...
closing as there hasn't been any activity and doesn't look like an actionable issue

@jasnell jasnell closed this as completed Mar 22, 2016
@dthree
Copy link
Author

dthree commented Mar 22, 2016

Meh. I'll do more research on it, and if I can get a better reproduction I'll file a more complete bug.

@fvydjt
Copy link

fvydjt commented May 3, 2023

The bug is still there and I meet it today. When I use conhost or git bash or powershell(on Windows Terminal), the problem arises. But in VScode integrated terminal, this problem only appear when I use command prompt(conhost) and it doesn't occur when I use bash or powershell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
process Issues and PRs related to the process subsystem. question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

6 participants