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

Separately bound keys are not firing together #43

Open
se-panfilov opened this issue Apr 12, 2024 · 2 comments
Open

Separately bound keys are not firing together #43

se-panfilov opened this issue Apr 12, 2024 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@se-panfilov
Copy link

se-panfilov commented Apr 12, 2024

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 se-panfilov changed the title Bonded keys are not fired together while pressing if they are not a combo; Binded keys are not fired together while pressing if they are not a combo Apr 12, 2024
@se-panfilov se-panfilov changed the title Binded keys are not fired together while pressing if they are not a combo Separately bound keys are not firing together Apr 12, 2024
@se-panfilov
Copy link
Author

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

@RobertWHurst
Copy link
Owner

Indeed, this is somewhat by design, though I must admit it's not great for games.

For applications, if I have the combo a + b, and a combo a + b + c, I don't really want the first combo firing. The behavior is that keys are consumed by the combos they trigger.

What might make better sense for the gaming use case it the ability to key keystrokes to allow non exclusive combo binds, and also allow overriding this setting when calling bind functions.

I'm quite busy these days, but I'm happy to take a PR until I find the time to do this myself.

Thanks for raising this.

@RobertWHurst RobertWHurst added enhancement New feature or request help wanted Extra attention is needed labels Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants