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
156 stars 6 forks source link

Gmail style key combinations allow other keys #23

Closed jasonish closed 1 year ago

jasonish commented 1 year ago

Describe the bug

I'm attempting to define Gmail style key combinations such as "g i", "g l", etc. However, the event triggers even if another letter was type inbetween.

To Reproduce

  bindKeyCombo("g, i", () => {
    console.log("goto inbox");
  });

Pressing g, release, press i works as expected.

However, typing "g x i", or "g a i", etc also triggers the event which is not expected.

Expected behavior

Sequences such as "g a i" should not trigger the event.

Other observations

There does not appear to be a timeout. I can press g, then hit i 10 or so seconds later and it triggers.

Thanks!

RobertWHurst commented 1 year ago

Just an update on this. This is due to how combo sequences transition between each other. Indeed this isn't how it should work - pressing random keys between sequences should cancel the combo. As for some form of timeout, I'll be working on that as well.

As for surrounding character presses, I don't believe those should interfere with observing a combo, so g g i shouldn't prevent g i from firing. If you want more granular control, you may want to bind several smaller combos and allow your program to control transitions between each.

I'll keep you posted, thanks for reporting this issue!

jasonish commented 1 year ago

I think I made a type in my expected behavior. Of course g g i should invoke the g i combo. I'll update the main description.

RobertWHurst commented 1 year ago

Cool stuff, yeah we can get this fixed. Thanks again @jasonish.

RobertWHurst commented 1 year ago

@jasonish just released v1.2.3. Give it a try and let me know if any issues come up for you.