Add support for keypress events
See original GitHub issueTo 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:
- Created 5 years ago
- Reactions:4
- Comments:21 (11 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I would like
useKeyHandler
to be built-in. It’s a very common need.Released
2.4.0
, which addsuseInput
hook.