JohannesKlauss / react-hotkeys-hook

React hook for using keyboard shortcuts in components.
https://react-hotkeys-hook.vercel.app/
MIT License
2.56k stars 112 forks source link

Match a key pressed by character (optionally maybe) instead of keyCode #1146

Closed jayarjo closed 4 months ago

jayarjo commented 4 months ago

Is your feature request related to a problem? Please describe.

With Finnish keyboard "/" comes by pressing shift-7, which is very different key from what we have in US keyboard. However a character itself is the same. From what I see react-hotkeys-hook doesn't currently support a character match, and relies on a keyCode instead.

Describe the solution you'd like

Technically it can be implemented via something like:

document.addEventListener('keypress', function(event) {
    // Check if the key pressed produces the "/" character
    if (event.key === '/') {
        // Activate the search bar
        console.log('Activating search bar'); // Replace this with the actual function to activate your search bar
    }
});

Describe alternatives you've considered

Register every possible combination of keys in all supported languages and also monitor somehow that language has changed. Not a viable solution.

JohannesKlauss commented 4 months ago

This will be added in version 5 with the Option useKey: true