question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong behavior on pressing different hotkey at the same time

See original GitHub issue

Version

4.0.4

Link to minimal reproduction

https://stackblitz.com/edit/react-p9vi6t?devToolsHeight=33&file=src/App.js

Steps to reproduce

  1. Register hotkey for UP, RIGHT, DOWN, LEFT
  2. Log the result in your own way
  3. Press [UP, RIGHT] at the same time (UP first)
  4. See the result / console log

What is expected?

Press [UP, RIGHT] at the same time => [‘UP’, ‘RIGHT’]

What is actually happening?

Press [UP, RIGHT] at the same time => [‘UP’, ‘UP’]

image

Case 2

Try this one, it’s even worse 😢 (see console log)

Press [UP, RIGHT] at the same time => [‘UP’, ‘RIGHT’, ‘UP’]

import React, { useState } from 'react';
import { useHotkeys } from 'react-hotkeys-hook';
import './style.css';

export default function App() {
  useHotkeys(
    'UP',
    () => {
      console.log('UP');
    },
    { preventDefault: true }
  );

  useHotkeys(
    'DOWN',
    () => {
      console.log('DOWN');
    },
    { preventDefault: true }
  );

  useHotkeys(
    'LEFT',
    () => {
      console.log('LEFT');
    },
    { preventDefault: true }
  );

  useHotkeys(
    'RIGHT',
    () => {
      console.log('RIGHT');
    },
    { preventDefault: true }
  );

  return (
    <div>
      <h1>react-hotkeys-hook</h1>
      <p>Pressing Arrow Button at the same time</p>
      <p>For example, press [UP, RIGHT] (try UP first)</p>
      <p>Then you will see the wrong pressed result</p>
      <br />
    </div>
  );
}

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Reactions:2
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
psychedeliciouscommented, Nov 22, 2022

I have run into an issue which feels very similar.

For combination hotkeys which include meta e.g. meta+z (overriding undo on macOS), if you trigger the hotkey but do not release meta, any subsequent key presses on any other key (apparently except ctrl) trigger the hotkey again.

Demo: https://stackblitz.com/edit/react-eqz5gk?file=src/App.js

In v3 this issue did not occur.

edit: Issue still occurs when using mod instead of meta.

1reaction
pionxzhcommented, Dec 25, 2022

Does it happen in 4.1.0?

I just tested 4.1.0, and it’s good now. Thanks 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Oops! 10 Keyboard Shortcuts Users Keep Hitting by Mistake
Shortcuts like Ctrl + Shift + Esc (to open the Task Manager) and Ctrl + Alt + Del (to open a screen with...
Read more >
Random applications opening when pressing any key on the ...
Press the windows and alt key at the same time. This resolves the problem every time for me! Hope this helps.
Read more >
Keyboard Doing Random Things Instead of Typing ... - YouTube
... Things Instead of Typing in Windows 10 [2022 Solution]Are you facing an issue in which random applications open when you press any...
Read more >
AHK stops reacting to hotkeys after random time - Ask for Help
Hotkeys in AutoHotKey both obey a rule (suspension) and a have a default behavior (single-call) that may unintuitively lead to an apparent ...
Read more >
6 Windows Keyboard Shortcuts You Might Hit By Mistake
The default shortcut to show the Sticky Keys prompt is pressing Shift five times in a row. You can turn the feature off...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found