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

[BUG] "mod" key with keyup true does not work #1208

Open
victortimsit opened this issue Sep 12, 2024 · 4 comments
Open

[BUG] "mod" key with keyup true does not work #1208

victortimsit opened this issue Sep 12, 2024 · 4 comments

Comments

@victortimsit
Copy link

victortimsit commented Sep 12, 2024

"mod" key with keyup true does not work but it works with keydown true.

This doesn't log anything

useHotkeys(
    "mod", // Using "mod" doesn't work here, probably a react-hotkeys-hook bug
    () => {
      console.log("mod");
    },
    { keyup: true }
  );
@victortimsit victortimsit changed the title [BUG] React Hotkeys "mod" with keyup true does not work [BUG] "mod" key with keyup true does not work Sep 12, 2024
@tatwater
Copy link

tatwater commented Dec 2, 2024

The mod key actually maps to the control key on MacOS instead of command like the docs say. I do not know what it maps to on Windows.

@ajani2001
Copy link

I found an interesting workaround for this bug.

If you want to listen to both keyup and keydown events for the mod alias, you can just set ignoreModifiers: true

@ajani2001
Copy link

ajani2001 commented Dec 25, 2024

The source problem is that MacOS has modifiers with the same key names (control and meta), but their purpose differs from the purpose of the corresponding keys on other platforms. This is why we want to use the mod alias: the purpose of command on Mac is similar to purpose of ctrl on other platforms.

This bug comes from this line:

if (!metaKey && !ctrlKey) {

But it is not so easy to fix as it might seem. We cannot get information about either OS or keyboard type from the KeyboardEvent and cannot distinguish between Mac's and other platforms' controls and metas. So, this bug requires deeper change in code to be fixed properly than it might seem. I suppose, we should keep the information about pressed mod somewhere to build the required logic for this alias.

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