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] Currently pressed key is not removed if shift is released first #1064

Open
damusnet opened this issue Aug 10, 2023 · 4 comments
Open
Labels
bug Something isn't working Version 5.x These tickets will be solved in Version 5.x

Comments

@damusnet
Copy link

Describe the bug
The order in which combo keys are released matters, when it should not.

To Reproduce

  1. Setup a shift+? hotkey
  2. Press shift, press ?, release shift first, release ? second
  3. Press shift again
  4. Hotkey triggers, even though ? is not pressed

CodeSanbdox Repro

Expected behavior
Hotkey should not trigger again on shift only, since ? is not pressed anymore

Screenshots
image

@damusnet
Copy link
Author

damusnet commented Aug 10, 2023

After a bit of investigation, this sort of makes sense. When pressing combo keys, the following is (roughly) registered:

  • Add shift
  • Add ?
  • Remove shift
  • Remove / <= that's the issue ; it's because without the shift, the ? key is now registered as a / key. So ? is never removed from the currently pressed keys, and any press to shift triggers the combo again.

This is on a en-US keyboard, but I suspect it's true for any shift combo on any keyboard. The particular key here is:

┌─────┐
│  ?  │
│  /  │
└─────┘

Not sure how best to fix this, as I don't fully understand the entire implementation logic.

Incidentally, pressing / then shift, which should (could?) produce the shift+?, does not work either.

@tamerxkilinc
Copy link

I solved this by doing the same as for the command key. On macOS the keyup event of letters and digits is not triggering while holding the command key down. That's why you can't just remove single keys of the array but need to clear it. The way I solved this also worked for the shift key!

Set a timeout each time shift is pressed. When it is released, instead of trying to remove the specific characters which were pressed with the shift key, the array of pressed keys is cleared completely. This ensures that you have no characters left in the pressed keys array.

@JohannesKlauss
Copy link
Owner

Yes this is currently a problem, because the library mixes the produces symbol with the produced key code. This will be fixed in version 5.

@JohannesKlauss JohannesKlauss added bug Something isn't working Version 5.x These tickets will be solved in Version 5.x labels Nov 21, 2023
@JohannesKlauss
Copy link
Owner

This is a layout specific problem that gets addressed in version 5.

This has been fixed in pre release 5.0.0-1. Please try out this version.
To listen to = use you just use useHotkeys('=', callback, {useKey: true})

Please let me know if that fixes your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Version 5.x These tickets will be solved in Version 5.x
Projects
None yet
Development

No branches or pull requests

3 participants