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

[BUG] 'meta/shift/alt+-' is not working

Open javoski opened this issue 2 years ago • 13 comments

Describe the bug Modifiers like meta/shift/alt combined with '-' is not working, but ctrl+- does.

To Reproduce Steps to reproduce the behavior:

  1. Go to the official website
  2. Edit one of those code examples to meta+-
  3. Press meta+-
  4. Nothing happened

It is the same with my real project.

Please try and add a codesandbox or stackblitz to reproduce the bug: <-- Link to reproducable -->

Expected behavior meta/shift/alt+- working as expected.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • macOS 12.6.3
  • Chrome 110.0.5481.177

javoski avatar Mar 16 '23 03:03 javoski

Cannot reproduce that on the webpage. Events are triggering fine. Please add an isolated reproducible.

Mind you, that after editing the code on the website you have to refocus the Live Editors output in order to make the hotkeys work, since they are all scoped to that output.

JohannesKlauss avatar Mar 19 '23 08:03 JohannesKlauss

Thanks for the reply, here is a codesandbox reproduction link: https://codesandbox.io/p/sandbox/musing-christian-ys7uoc

javoski avatar Mar 19 '23 14:03 javoski

I'm also facing an issue where meta+, doesn't work

timnlupo avatar Mar 22 '23 18:03 timnlupo

@javoski I am still not able to reproduce this, works absolutely fine for me on Chrome and mac. I am on macOS 11 though, so I'll update to 12. But still, are you sure that there aren't any custom system key mappings that filter out that event? What's the console output on this sandbox if you hit the meta+- for example? https://codesandbox.io/s/react-hotkeys-template-bzvk53

@timnlupo Did you set the splitKey option to something else? , defines a combination split by default. In order to use it as part of a key combination you have to set the splitKey option to a different key.

JohannesKlauss avatar Mar 24 '23 08:03 JohannesKlauss

What's the console output on this sandbox if you hit the meta+- for example? https://codesandbox.io/s/react-hotkeys-template-bzvk53

Nothing happened but the web page zoom-out.

FYI, it's working when I use meta+minus instead.

javoski avatar Mar 24 '23 09:03 javoski

I had the exact same issue. meta+minus works for me too. Using macOS 13.2.1

zstiggz avatar Mar 24 '23 19:03 zstiggz

I'm also facing an issue where meta+, doesn't work

This doesn't work for me either. I've confirmed it works still with v4.3.5/6/7 but v4.3.8 it does not. Codesandbox

TravisL12 avatar Apr 04 '23 21:04 TravisL12

Actually changing the splitKey does get around the issue:

useHotkeys(
    ["Meta+Shift+,"],
    () => {
      setCount(count + 1);
    },
    { splitKey: "-" } // change this to something else and it works
  );

A decent workaround for the moment.

EDIT: I guess you could argue this isn't a bug to begin with, it's certainly a collision of a hotkey definition. But since there is an override option already available I wonder if there somehow just needs some clarification regarding the choice of key combinations.

TravisL12 avatar Apr 04 '23 21:04 TravisL12

With v4.4.0, I seem to be seeing this issue as well with both shift+plus and shift+= even without using meta.

The work around above did not work in this case.

xbreid avatar May 25 '23 09:05 xbreid

I encountered the same issue, wanting to add a hotkey on shift+plus and tried everything (plus, +, changing the splitKey, etc.). Ultimately, a look at the code gave me a working - albeit strange - solution:

https://github.com/JohannesKlauss/react-hotkeys-hook/blob/92bb90e7eb61962cf0eadcbd068f849652e39fd3/src/parseHotkeys.ts#L14

useHotkeys("shift+bracketright", () => { alert("'shift +' was pressed") });

damusnet avatar Aug 02 '23 13:08 damusnet

looks like that solution works for shift, but not for the meta key .

The following doesn't seem to work for me:

useHotkeys("meta+bracketright", () => { alert("'meta +' was pressed") });

Marc-Roig avatar Aug 20 '23 10:08 Marc-Roig

Is there a plan to fix this bad mapping? using bracketright for plus works, but also adds a hotkey on the ] key

localyost3000 avatar Nov 27 '23 16:11 localyost3000

Note that the shift+bracketright for "shift +" worked until version 4.4.1, but stopped working in 4.4.4 and 4.5.0

damusnet avatar Feb 01 '24 18:02 damusnet