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] isHotkeyPressed does not work inside a hook callback #1225

Open
punkpeye opened this issue Nov 22, 2024 · 1 comment
Open

[BUG] isHotkeyPressed does not work inside a hook callback #1225

punkpeye opened this issue Nov 22, 2024 · 1 comment

Comments

@punkpeye
Copy link

Describe the bug

isHotkeyPressed does not work inside a hook callback.

To Reproduce

const combos = Object.fromEntries(
  commands
    .filter(({ combo }) => {
      return combo;
    })
    .map((command) => {
      if (!command.combo) {
        throw new UnexpectedStateError('Expected to find a combo');
      }

      return [command.combo.join('+'), command];
    }),
);

useHotkeys(Object.keys(combos), (event) => {
  console.log('> 1', combos, event);

  for (const [combo, command] of Object.entries(combos)) {
    if (isHotkeyPressed(combo)) {
      console.log('> 2', command);
    }
  }
});

I need to dynamically bind hot keys.

In this case, a key would be meta+/.

The > 1 triggers, but > 2 does not.

@punkpeye
Copy link
Author

As far as I can tell, event does not identify which combo was triggered.

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

1 participant