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] Switching to colemak causes multiple keystrokes to be registered. #1039

Open
pashashocky opened this issue Jun 6, 2023 · 10 comments
Open
Labels
bug Something isn't working Version 5.x These tickets will be solved in Version 5.x

Comments

@pashashocky
Copy link

Describe the bug
Multiple keystrokes registered with colemak layout:

To Reproduce

  1. Switch to "Colemak" layout
  2. Hit d key on qwerty which is s on colemak.

Please try and add a codesandbox or stackblitz to reproduce the bug:

import "./App.css";
import React from "react";
import { useHotkeys } from "react-hotkeys-hook";

function App() {
  const [countS, setCountS] = React.useState(0);
  const [countD, setCountD] = React.useState(0);

  useHotkeys("s", () => setCountS((count) => count + 1));
  useHotkeys("d", () => setCountD((count) => count + 1));

  return (
    <>
      <h1>Pressed 's' key {countS} times.</h1>
      <h1>Pressed 'd' key {countD} times.</h1>
    </>
  );
}

export default App;

Expected behavior
Single key press should register single keystroke

Screenshots
Dropover Video

@TristanH
Copy link

TristanH commented Jun 7, 2023

We're seeing this issue too in our app!

@JohannesKlauss
Copy link
Owner

JohannesKlauss commented Jun 23, 2023

Yes, this is related to this issue. I am working on a version 5 that only listens to the produced key. But I am super busy right now, so this might take some time.

@JohannesKlauss JohannesKlauss added bug Something isn't working Version 5.x These tickets will be solved in Version 5.x labels Jun 23, 2023
@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 d no matter the layout useHotkeys('d', callback, {useKey: true})

Please let me know if that fixes your issue.

@matiastucci
Copy link

@JohannesKlauss I tried { useKey: true } but I still see an issue:

In Dvorak layout if I press h 1 time I'm seeing the d callback firing too. So, in this example if I press h (on dvorak) I'm seeing both counts increase.

function Test() {
  const [countH, setCountH] = React.useState(0);
  const [countD, setCountD] = React.useState(0);

  hotkeys.useHotkeys('d', () => setCountD((count) => count + 1), { useKey: true });
  // In dvorak pressing the 'h' key is the same as pressing the 'd' key in qwerty
  hotkeys.useHotkeys('h', () => setCountH((count) => count + 1), { useKey: true });

  return (
      <>
        <h1>Pressed D key {countD} times.</h1>
        <h1>Pressed H key {countH} times.</h1>
      </>
  );
}

@JohannesKlauss
Copy link
Owner

That is weird. If you log the event, what is the produced key?

@matiastucci
Copy link

Both events have the same: key: "d" and keyCode: 68

@JohannesKlauss
Copy link
Owner

Hmh... but in general the Keys work correct (in a textinput for example?)

@matiastucci
Copy link

yeah, that works fine. The issue is seeing 2 events fired when pressing only 1 key.

In my app I have actions associated with h and d and on Dvorak when pressing h the 2 actions (d too) are firing instead of only 1.

@JohannesKlauss
Copy link
Owner

What happens if you add a third one with the following and hit d:

useHotkeys('*', e => console.log(e))

Can you show me the logs?

@matiastucci
Copy link

Yeah, no problem. I did and when pressing d on Dvorak I get: { key: "e", charCode: 0, keyCode: 69 }.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Version 5.x These tickets will be solved in Version 5.x
Projects
None yet
Development

No branches or pull requests

4 participants