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

slash, backslash, and bracketright are not defined correctly in parseHotkeys.ts #1125

Open
luispied opened this issue Jan 23, 2024 · 9 comments

Comments

@luispied
Copy link

luispied commented Jan 23, 2024

I found this bug that was giving me a hard time in my repo until I dig in into your code and found what was the issue.

Everytime I hit '-' it behaves as '/', I detected it as I have one hotkey for each of this keys, I tried a lot of different things in my repo and didn't get it fix.

You need to change - in favor of / that is the actual slash and not a hyphen

Also in the same file:

'#': 'backslash', // this should be '': 'backslash',
'+': 'bracketright', // this should be ']': 'bracketright',

@luispied luispied changed the title I found this bug that was giving me a hard time in my repo slash, backslash, and bracketright are not defined correctly in parseHotkeys.ts Jan 23, 2024
@adam-vermes
Copy link

adam-vermes commented Jan 29, 2024

I have a similar issue with the '-': 'slash' key where it doesn't trigger the expected behaviour as in earlier versions. Could you please take a look at this issue? Thanks

@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.

@thediveo
Copy link

Not the OP, but it fixes the "/" slash for me; thank you very much!

@luispied
Copy link
Author

Hi @JohannesKlauss I recently update to version 5.0.0-1 and tried to see if that fixed my issue, but it doesn't.
I was using ignoreModifiers on the callback for the hook so when I tried to input / in different keyboard distribution it worked, but now it stoped working, so I read about the new option useKey that will probably helped me to achieve the same and sadly it does not.
Idk if im doing something wrong but would be great if you can explain me how can I achieve this behavior with all the new changes in this new version.

To be clear and have a use case for you to reproduce it, I selected the key / to trigger an action, it works perfectly in U.S English distribution in Mac, but then I changed the distribution to for example Canadian French CSA and it doesn't worked, even sending useKey:true. I tried a combination between useKey and ignoreModifiers but same result.

@JohannesKlauss
Copy link
Owner

This is the way to use special characters that are different on different layouts:

https://codesandbox.io/p/sandbox/lucid-ioana-c8zjcj

Please let me know if that works for you.

@luispied
Copy link
Author

This is the way to use special characters that are different on different layouts:

https://codesandbox.io/p/sandbox/lucid-ioana-c8zjcj

Please let me know if that works for you.

@JohannesKlauss Is what I did, but even in your sandbox I see the same issue as I have.

Perhaps I didn't explain myself correctly, what I want is that no matter the distribution when I press they key in the english keyboard / I want to trigger the callback, so for french canadian the key in the same position of the keyboard is é.

As I said I could achieved this behavior in the past using ignoreModifiers but somehow perhaps useKey and ignoreModifiers cancel this functionality themselves.

@JohannesKlauss
Copy link
Owner

JohannesKlauss commented Feb 21, 2024

Ah I see. Actually I have to look into ignoreModifiers, good chance that this option gets removed in version 5. To achieve this you would listen to the code of the key, in this case Slash:

useHotkeys("Slash", () => setCount(count + 1));

This way, no matter the keyboard layout, it will always listen to the key which is the slash key in US layout.

@luispied
Copy link
Author

Ah I see. Actually I have to look into ignoreModifiers, good chance that this option gets removed in version 5. To achieve this you would listen to the code of the key, in this case Slash:

useHotkeys("Slash", () => setCount(count + 1));

This way, no matter the keyboard layout, it will always listen to the key which is the slash key in US layout.

I forgot about slash, I tried before.

The good news is that worked for me, so thank you so much @JohannesKlauss.

Can I suggest to add this to documentation as a use case, because I didn't see it there and would be very helpful for other devs.

Also I would want to suggest if it's possible to include the types for all the key strokes in the call of the hook, as useHotkeys(keys: KeysType[], callback, options). You have a link to another library that did that in the documentation, perhaps include it inside the library will improve the use of it and reduce the errors.

@JohannesKlauss
Copy link
Owner

Well version 5.0.0 is not officially out yet, I am currently overhauling the docs, but yes, this will be documented.

I am unsure about the typings, because the keys type can be a lot of different things.

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