Wrong behavior on pressing different hotkey at the same time
See original GitHub issueVersion
4.0.4
Link to minimal reproduction
https://stackblitz.com/edit/react-p9vi6t?devToolsHeight=33&file=src/App.js
Steps to reproduce
- Register hotkey for
UP
,RIGHT
,DOWN
,LEFT
- Log the result in your own way
- Press [
UP
,RIGHT
] at the same time (UP
first) - 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’]
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:
- Created 10 months ago
- Reactions:2
- Comments:11 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 releasemeta
, any subsequent key presses on any other key (apparently exceptctrl
) 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 ofmeta
.I just tested 4.1.0, and it’s good now. Thanks 🙏