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

[BUG] Does not handle the 'Alt Graph' modifier key #1143

Open moloko opened 4 months ago

moloko commented 4 months ago

If I create a simple, single-key shortcut, like this:

useHotkeys("c", (e) => console.log('shortcut activated'));

I would expect it not to activate when the Alt Gr modifier key is held down, as per other modifer keys such as , , , Ctrl etc. - but it does.

I've set up a demo of this here, although obviously you'll need to access this from Windows to be able to replicate!

I have checked this in Windows 10 using Chrome and Edge.

It looks to me like the best method for detecting the use of this modifier key is via event.getModifierState('AltGraph').

I'm happy to have a go a fixing this if you want, just let me know.

JohannesKlauss commented 2 months ago

If you have time, please add a PR for that 🙂