Closed oceandrama closed 5 months ago
Your example contains the same key combinations, so it will trigger on both or none.
I made this example for easier reproducing. It happens on Windows if you use different keyboard layouts like
useHotkeys(['Shift+Г', 'Shift+U'])
If you press Г
(which on the same place with U
) callback calls twice, but if you remove it, it doesn't call on this layout
Find first matching key will be very helfull in this situation
I think I don't quite understand your use case. What are you trying to achieve? If you listen to the same key twice, the callback will fire twice. So, what are you trying to achieve by listening twice for the same combination in the first place?
Describe the bug If user sets multiple keys in one hook like this:
callback will be triggered on each key
Expected behavior Callback triggered once on the first matched key
Additional context It happens because of
forEach
in this line https://github.com/JohannesKlauss/react-hotkeys-hook/blob/9bfa17c69dc407f10ecfb0aa18d7ccf536da8d4b/src/useHotkeys.ts#L85 instead of finding first matched key