RobertWHurst / Keystrokes

Keystrokes as an easy to use library for binding functions to keys and key combos. It can be used with any TypeScript or JavaScript project, even in non-browser environments.
MIT License
137 stars 5 forks source link

Separately bound keys are not firing together #43

Open se-panfilov opened 3 months ago

se-panfilov commented 3 months ago

Describe the bug If you are binding some keys separately, e.g.

const coords = { x: 0, y: 0 };

bindKey('w', () => coords.x += 1  );
bindKey('a', () => coords.y -= 1  );
bindKey('s', () => coords.x -= 1  );
bindKey('d', () => coords.y += 1  );

While pressing 2 keys (or more), only one of the callback is triggered. (But all should be triggered, imo)

Expected behavior I expect both callbacks to be triggered at the same time, cause 2 buttons are still pressed.

Why Imagine a videogame, e.g. a shooter game. User is moving using WASD alongside with "space" for a jump, "G" for throwing grenade and etc. It's literary impossible to bind every combo. Instead the binds should be independent from each other ("W" moves forward, "A" moves left, so eventually user will be moved forward and left) .

To Reproduce An example at stackblitz: https://stackblitz.com/edit/vitejs-vite-iunkan?file=src%2Fmain.ts

You can move the "Actor" red square using WASD, but cannot move it in a diagonal direction.

P.S. used version 1.5.6

se-panfilov commented 2 months ago

Is it any chance that this issue will be fixed? =)