-
Notifications
You must be signed in to change notification settings - Fork 246
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
feat(keyboard): keep key pressed for multiple keydown
events
#728
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 2a46dc2:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all thanks a lot for taking the time to contribute. ❤️
The implementation does not properly solve the issue yet.
When a key is pressed in the browser, the browser dispatches a keydown
event every n
ms.
(Usually there is a primary delay before the key is considered "pressed" and then there is a secondary delay between each of the keydown
events until the key is released or another one is either pressed or released - both usually according to some system setting.)
For each of the keydown
events there might be the default behavior of a keypress
and depending on the active element an input
event.
Instead of dispatching each event multiple times the whole implementation needs to loop for fireKeyDownTimes
.
@ph-fritsche Thank you for explaining how triggering keyboard events work in browser. That's great something I was not aware of. It's great learning opportunity for me, I'll definitely dig deeper into the topic and the source code of library 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started with a review but achieving this while keeping the code readable required quite some refactoring so I opened a PR.
fix: only trigger one `keyup` for repeated `keydown`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed that we might leak state into another call if the last key def has a repeat modifier and keyboardState
is reused on another call.
Codecov Report
@@ Coverage Diff @@
## main #728 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 51 51
Lines 994 1005 +11
Branches 413 408 -5
=========================================
+ Hits 994 1005 +11
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me now.
keydown
events
@patricklizon Could you file a PR for the docs? |
@all-contributors add @patricklizon code |
I've put up a pull request to add @patricklizon! 🎉 |
🎉 This PR is included in version 13.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What:
Trigger multiple keydown events in a single key press
Why:
As requested in #618
How:
I followed @ph-fritsche suggestions #618 (comment)
repeatModifier
detection atgetNextKeyDef
repeatKey
tokeyboardState
Checklist: