useKeyPress doesn't track repeated combination keypresses until the entire combination is released
See original GitHub issueDescribe the Bug
When using useKeyPress
to track combinations of keys, for example Meta+z
, repeated keypresses are not captured if you continue to hold down the Meta
key.
Your Example Website or App
https://codesandbox.io/s/recursing-driscoll-stvwou?file=/src/App.js
Steps to Reproduce the Bug or Issue
When const comboPressed = useKeyPress("Meta+z");
:
- Press and hold
Meta
- Press and hold
z
comboPressed
is true- Release
z
comboPressed
is still true and so additional presses ofz
can’t be detected- Release
Meta
comboPressed
is now false
The inverse does not have the same behaviour:
- Press and hold
z
- Press and hold
Meta
comboPressed
is true- Release
Meta
comboPressed
is now false and so additional presses ofz
can be detected
Expected behavior
As a user I would expect that after I press Meta and z
, and then continue to hold Meta
but release z
that the pressed state of useKeyPress("Meta+z")
is false.
Screenshots or Videos
No response
Platform
- OS: macOS
- Browser: Chrome
- Version: 103.0.5060.53
Additional context
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5 (4 by maintainers)
Top Results From Across the Web
useKeyPress React Hook - useHooks
Hooks are a feature in React that allow you use state and other React features without writing classes. This website provides easy to...
Read more >Detecting combination keypresses (Control, Alt, Shift)?
The keypress event is fired as soon as a key has been pressed. If you are pressing multiple keys ...
Read more >Detect single and multiple keypress events: JavaScript
When we use a 'keydown' event we are listening for the moment when a key is pressed. We can similarly react when a...
Read more >UI Events - W3C
The DOM Event Model allows a DOM implementation to support multiple modules of events. The model has been designed to allow addition of...
Read more >Keyboard shortcuts, hotkeys, and special keys (Windows)
You can use key press combinations to perform common tasks in Windows. ... Copy a picture of the current window (not the entire...
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 FreeTop 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
Top GitHub Comments
Ok, thanks. We will need to check how other libs handle this
IMO, it should use
keydown
event instead ofkeypress
event. The following code is what I have tried withoutuseKeyPress
API, and it seems workingNote. this example is using state management library