react-hotkeys-hook icon indicating copy to clipboard operation
react-hotkeys-hook copied to clipboard

[BUG] Hotkeys for 'z' and 'y' not working correctly when using ISO keyboard layout

Open EricBlommel opened this issue 2 years ago • 5 comments
trafficstars

Describe the bug It doesn't matter if I press 'y' or 'z' on my keyboard. The callbacks for both keys are triggered.

To Reproduce Steps to reproduce the behavior:

useHotkeys(['ctrl+z', 'z'], (keys) => console.log(keys)); useHotkeys(['ctrl+y', 'y'], (keys) => console.log(keys));

Expected behavior A clear and concise description of what you expected to happen. if I press 'y' than only y the callback of y should be triggered. The same for z

Desktop (please complete the following information):

  • OS: MacOS Ventura 13.4
  • Browser chrome
  • Version 114.0.5735.133

EricBlommel avatar Jun 20 '23 09:06 EricBlommel

Yes, this is related to this issue. I am working on a version 5 that only listens to the produced key. But I am super busy right now, so this might take some time.

JohannesKlauss avatar Jun 23 '23 15:06 JohannesKlauss

Yes, this is related to this issue. I am working on a version 5 that only listens to the produced key. But I am super busy right now, so this might take some time.

I'm not sure if this is related, but it doesn't look like the "esc" or "escape" key is firing an event when bound.

clickar14 avatar Jun 29 '23 17:06 clickar14

I ran into the same issue. You can check the first argument of the callback for the key which always seems to have the correct key that is pressed.

After pressing ctrl+z, the following event handler fires :grimacing:

useHotkeys(
  ['ctrl+y, command+y'],
  ({ key, ...rest }, handler) => {
    if (key === 'z') {
      return
    }

    // Now handle the actual ctrl+y event but beware: handler.keys === ['z'] 
  }
)

This is quite a big bug imo, would there be any way to patch it within v4?

CodingDive avatar Jul 19 '23 09:07 CodingDive

This would be a breaking change, so it's not feasible to fix it in version 4, sorry.

JohannesKlauss avatar Jul 25 '23 08:07 JohannesKlauss

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 y use you just use useHotkeys('y', callback, {useKey: true})

Please let me know if that fixes your issue.

JohannesKlauss avatar Feb 09 '24 10:02 JohannesKlauss