question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for keypress events

See original GitHub issue

To be able to have the component rerendered on keypresses and get the keys.

Ink would need to do readline.emitKeypressEvents(stdin); in https://github.com/vadimdemedes/ink/blob/master/src/components/App.js#L61 And it requires raw-mode.

After enabling the above, Ink could do something like this internally:

process.stdin.on('keypress', (str, key) => {
    if (key.ctrl && key.name === 'f') {
        console.log('foo')
    }
})

My initial idea was to expose a useKeypress() React hook. @vadimdemedes suggested we could just expose the keypresses by default if raw-mode is activated, as the output is being diffed anyway, so the cost is negligible.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:21 (11 by maintainers)

github_iconTop GitHub Comments

5reactions
sindresorhuscommented, Jun 18, 2019

I would like useKeyHandler to be built-in. It’s a very common need.

3reactions
vadimdemedescommented, Sep 26, 2019

Released 2.4.0, which adds useInput hook.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Element: keypress event - Web APIs | MDN
The keypress event is fired when a key that produces a character value is pressed down.
Read more >
Introduction to Keyboard Events in JavaScript - Section.io
In this article we will learn about what keyboard events are, and explore different keyboard events. We will also build a simple game...
Read more >
onkeypress Event - W3Schools
The onkeypress event occurs when the user presses a key (on the keyboard). Tip: The order of events related to the onkeypress event:...
Read more >
JavaScript Keyboard Events Explained
When you press a non-character key, the keydown event is fired first followed by the keyup event. If you hold down the non-character...
Read more >
.keypress() | jQuery API Documentation
Description: Bind an event handler to the "keypress" JavaScript event, or trigger that event on an element. version added: 1.0.keypress( handler ). handler....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found