jaywcjlove / hotkeys-js

➷ A robust Javascript library for capturing keyboard input. It has no dependencies.
https://jaywcjlove.github.io/hotkeys-js
MIT License
6.61k stars 406 forks source link

Fix incorrect order of downKeys #432

Open YuxuanWeng opened 1 year ago

YuxuanWeng commented 1 year ago

I discovered that when using hotkeys('*', {keyup:true, keydown:true}, handler), with the keyup and keydown options set to true, if there are other hotkeys('*', {}, handler2) listeners present, the _downKeys order gets rearranged. This causes an issue when I'm implementing keyboard shortcuts persistence because the order of keycodes retrieved using getPressedKeyCodes after keyup is incorrect.

Here is the reproducible link: https://codesandbox.io/s/eager-pond-cstwrz?file=/src/App.tsx

jaywcjlove commented 1 year ago

@YuxuanWeng Your fix has been reverted because it caused some problems with scope. #434

YuxuanWeng commented 1 year ago

https://codesandbox.io/s/eager-pond-cstwrz?file=/src/App.tsx @jaywcjlove 大佬可以看下这个case吗?先按住cmd再按住k,getPressedKeyString的结果会出现k+cmd,而不是cmd+k

jaywcjlove commented 1 year ago

先摁的 k 键,再摁 cmd 会出现这种问题,我想了一下,如果先摁 c 再摁 cmd 也不能复制

重现问题

按住 cmd ,第一次按 k 返回 cmd+k, 不松开 cmd 第二次按 k 返回 k+cmd