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

Support key events (eg onkeydown) #14483

Open
jakeg opened this issue Oct 11, 2024 · 1 comment
Open

Support key events (eg onkeydown) #14483

jakeg opened this issue Oct 11, 2024 · 1 comment
Labels
enhancement New feature or request node.js Compatibility with Node.js APIs

Comments

@jakeg
Copy link
Contributor

jakeg commented Oct 11, 2024

What is the problem this feature would solve?

Currently listening for keyboard input in Bun either involves waiting for a user to hit enter after a prompt() or using process.stdin like this:

process.stdin.setRawMode(true)
process.stdin.on('data', (e) => {
  console.log(e)
    if (e[0] == 32) {
      console.log('Spacebar pressed')
      process.stdin.setRawMode(false)
    }
})

What is the feature you are proposing to solve the problem?

What if Bun supported key events instead, like browsers.

onkeydown = (e) => {
  if (e.key === ' ') {
    console.log('Spacebar pressed')
  }
}

What alternatives have you considered?

No response

@jakeg jakeg added the enhancement New feature or request label Oct 11, 2024
@Jarred-Sumner
Copy link
Collaborator

interesting idea

it's a bit tricky because for terminals you need to enter "raw mode" which means you can't press ctrl + c anymore and a few other things

@nektro nektro added the node.js Compatibility with Node.js APIs label Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request node.js Compatibility with Node.js APIs
Projects
None yet
Development

No branches or pull requests

3 participants