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

useInput keys not responding properly (ctrl, backspace, shift) #512

Closed
jrson83 opened this issue Apr 9, 2022 · 4 comments
Closed

useInput keys not responding properly (ctrl, backspace, shift) #512

jrson83 opened this issue Apr 9, 2022 · 4 comments

Comments

@jrson83
Copy link

jrson83 commented Apr 9, 2022

This is related to #409

There is something really wrong with the key detection.

ctrl & tab

For me on both linux and windows, key.ctrl doesn't get detected at all, when pressing ctrl.

Instead when pressing tab, both key.tab and key.ctrl getting detected.

You can check with logging:

useInput((input, key) => {
  console.log(key)
}

// output when pressing TAB
{
  upArrow: false,
  downArrow: false,
  leftArrow: false,
  rightArrow: false,
  pageDown: false,
  pageUp: false,
  return: false,
  escape: false,
  ctrl: true,
  shift: false,
  tab: true,
  backspace: false,
  delete: false,
  meta: false
}

backspace & delete

key.del gets detected when pressing del. But when pressing backspace it does not detect key.backspace, but instead key.del.

useInput((input, key) => {
  console.log(key)
}

// output when pressing BACKSPACE
{
  upArrow: false,
  downArrow: false,
  leftArrow: false,
  rightArrow: false,
  pageDown: false,
  pageUp: false,
  return: false,
  escape: false,
  ctrl: false,
  shift: false,
  tab: false,
  backspace: false,
  delete: true,
  meta: false
}

shift

When pressing shift it does not get detected at all.

@manast
Copy link

manast commented Apr 14, 2022

Yeah it has a funny behaviour I just noticed this in MacOS. I could confirm these weird things:

  • shift only gets to true if pressed together with a character, not with the arrows and not with any other key or alone.
  • Pressing tab sets both tab and ctrl to true.
  • Pressing ctrl alone is not detected, but together with other characters yes.
  • Pressing alt by its own is not detected, however pressing alt+arrows it gets detected as meta, however the arrows themselves are not detected :(.
  • esc sets both meta and esc to true.

Probably other stuff, I did not test everything...

@vadimdemedes
Copy link
Owner

None of the modifier keys (e.g. shift, control, option or command) are expected to trigger a press event. They're only expected to trigger events when used in combination with "regular" keys.

This matches the built in behavior of keypress events in Node.js. You can test this yourself with this simple script:

import readline from 'node:readline';

readline.emitKeypressEvents(process.stdin);

process.stdin.setRawMode(true);

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

	if (key.name === 'q') {
		process.exit(0);
		return;
	}
});

esc sets both meta and esc to true.

This also matches the keypress event in Node.js.

Pressing tab sets both tab and ctrl to true.

This and

pressing alt+arrows it gets detected as meta, however the arrows themselves are not detected :(.

this are bugs indeed. Will work on a fix.

@jrson83 As for behavior on Linux or Windows, I don't have access to these OSes, so I'd appreciate a PR.

vadimdemedes added a commit that referenced this issue Mar 28, 2023
vadimdemedes added a commit that referenced this issue Mar 28, 2023
@vadimdemedes
Copy link
Owner

vadimdemedes commented Mar 28, 2023

Pushed 26b8364 to stop enabling ctrl for Tab and 8180c1c to detect arrow keys when pressed together with meta key.

@vadimdemedes
Copy link
Owner

Merged #576, so Ink should now parse keyboard the same as readline in Node.js would.

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