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

[BUG] - released key is still considered pressed #294

Open
pau-not-paul opened this issue Oct 14, 2020 · 3 comments
Open

[BUG] - released key is still considered pressed #294

pau-not-paul opened this issue Oct 14, 2020 · 3 comments

Comments

@pau-not-paul
Copy link

Describe the bug
When typing a capital letter using shift (shift+letter), sometimes it registers the keydown event for the upper case letter but then it registers the keyup event for the lower case letter. Since it doesn't have a keyup event for the upper case letter, it thinks that it's still presses

How are you using react hotkeys components? (HotKeys, GlobalHotKeys, IgnoreKeys etc)
It happens in all the use cases.

Expected behavior
It should detect that the key has been released.

Platform (please complete the following information):
It happens with Chrome, Firefox, Safari...

Are you willing and able to create a PR request to fix this issue?
No, because I found a workaround:

configure({
  ignoreEventsCondition: (e) => {
    // This is a hack to solve an issue in react-hotkeys.
    // Sometimes it thinks that a letter is still pressed.
    // It happens when you type shift+letter and it registers
    // the keydown event of the letter as upper case, but it
    // registers the keyup event as lower case. Since there's
    // no keyup event for the upper case letter it thinks
    // that it's still pressed
    return !e.altKey && !e.ctrlKey && !e.metaKey && e.shiftKey;
  },
});

Include the smallest log that includes your issue:

HotKeys (GLOBAL-E1💚): New 'Shift' keydown event (that has NOT passed through React app).
HotKeys (GLOBAL-C1⭐️): No matching actions found for 'Shift' keydown.
HotKeys (GLOBAL-E2💙): New (simulated) 'Shift' keypress event (that has NOT passed through React app).
HotKeys (GLOBAL-E2💙): Ignored 'Shift' keypress because it doesn't have any keypress handlers.
HotKeys (GLOBAL-E3💛): New 'E' keydown event (that has NOT passed through React app).
HotKeys (GLOBAL-C1⭐️): No matching actions found for 'Shift+E' keydown.
HotKeys (GLOBAL-E4💜): New 'E' keypress event (that has NOT passed through React app).
HotKeys (GLOBAL-E4💜): Ignored 'Shift+E' keypress because it doesn't have any keypress handlers.
HotKeys (GLOBAL-E5🧡): New 'Shift' keyup event (that has NOT passed through React app).
HotKeys (GLOBAL-E5🧡): Ignored 'Shift+E' keyup because it doesn't have any keyup handlers.
HotKeys (GLOBAL-E6❤️): New 'l' keydown event (that has NOT passed through React app).
HotKeys (GLOBAL-C1⭐️): No matching actions found for 'E+l' keydown.
HotKeys (GLOBAL-E7💚): New 'l' keypress event (that has NOT passed through React app).
HotKeys (GLOBAL-E7💚): Ignored 'E+l' keypress because it doesn't have any keypress handlers.
HotKeys (GLOBAL-E8💙): New 'e' keyup event (that has NOT passed through React app).

What Configuration options are you using?
It happens with the default config.

@mikhuang
Copy link

mikhuang commented Oct 29, 2020

The workaround doesn't seem to work for scenarios in which one is trying to capture both 'command+z' and 'command+shift+z':

  • keydown 'command+z' -> triggers as expected
  • releasing 'z' while continuing to hold 'command'
  • keydown on 'shift' -> triggers 'command+shift+z' unexpectedly

Log

HotKeys (GLOBAL-E21💛): New 'Meta' keydown event (that has NOT passed through React app).
HotKeys (GLOBAL-E21💛): Added 'Meta' to current combination: 'Meta'.
HotKeys (GLOBAL-E21💛): Attempting to find action matching 'Meta' keydown . . .
HotKeys (GLOBAL-E21💛-C0🔺): No matching actions found for 'Meta' keydown.
HotKeys (GLOBAL-E22💜): New (simulated) 'Meta' keypress event (that has NOT passed through React app).
HotKeys (GLOBAL-E22💜): Ignored 'Meta' keypress because it doesn't have any keypress handlers.

HotKeys (GLOBAL-E23🧡): New 'z' keydown event (that has NOT passed through React app).
HotKeys (GLOBAL-E23🧡): Added 'z' to current combination: 'Meta+z'.
HotKeys (GLOBAL-E23🧡): Attempting to find action matching 'Meta+z' keydown . . .
HotKeys (GLOBAL-E23🧡-C0🔺): Found action that matches 'Meta+z': UNDO. Calling handler . . .
HotKeys (GLOBAL-E23🧡-C0🔺): Stopping further event propagation.
HotKeys (GLOBAL-E23🧡): Searching no further, as handler has been found (and called).

// z released

HotKeys (GLOBAL-E24❤️): New (simulated) 'z' keypress event (that has NOT passed through React app).
HotKeys (GLOBAL-E24❤️): Ignored 'Meta+z' keypress because it doesn't have any keypress handlers.

// shift pressed

HotKeys (GLOBAL-E25💚): New 'Shift' keydown event (that has NOT passed through React app).
HotKeys (GLOBAL-E25💚): Added 'Shift' to current combination: 'Meta+Shift+z'.
HotKeys (GLOBAL-E25💚): Attempting to find action matching 'Meta+Shift+z' keydown . . .
HotKeys (GLOBAL-E25💚-C0🔺): Found action that matches 'Meta+Shift+z': REDO. Calling handler . . .

...

@nopol10
Copy link

nopol10 commented Nov 7, 2020

Are you guys still having this problem? I was having an issue with nothing working after pressing spacebar and had to refocus the element to restore hotkey functionalities. I was using the package from npm.

I then cloned this repo locally and built it to figure out the issue and realized that the version on github is newer than the one in npm and the issue I was having wasn't present in this one. Maybe this had already been fixed but wasn't published?

@ivannovazzi
Copy link

ivannovazzi commented Dec 7, 2020

I am experiencing the same bug as well. I was experimenting with my very first combinations command+z (undo), command+shit+z(redo) and it resulted exactly is what @mikhuang reported above.

@akphi akphi mentioned this issue Sep 30, 2021
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants