hotkeys-js icon indicating copy to clipboard operation
hotkeys-js copied to clipboard

Whether support Sequence of keys?

Open xcv58 opened this issue 6 years ago • 16 comments

Hi,

I want to switch the shortcut implementation from Mousetrap to this library.

But I can't find whether the library supports the Sequence of keys feature in your doc. More details:

image

https://craig.is/killing/mice

Could you please confirm whether this library supports the feature? Thanks!

xcv58 avatar May 13 '18 05:05 xcv58

@xcv58 I looked at it and there should be no problem with migration.

jaywcjlove avatar May 13 '18 08:05 jaywcjlove

Great, thank you!

xcv58 avatar May 13 '18 17:05 xcv58

Hi @jaywcjlove

I probably put the Sequence of keys feature incorrectly. If I have such code:

    hotkeys('g o', (e) => {
      console.log('g o')
    })

The function should only fire if user enters g then o like the Gmail shortcut.

However, the callback function fires when I hit g immediately and it would check whether it's the consequence of g and o. Could you please double check whether your library supports this feature?

xcv58 avatar May 14 '18 00:05 xcv58

I read the shortcuts in Gmail. This shortcut is not supported.

image

Currently supports multiple forms: https://github.com/jaywcjlove/react-hotkeys/issues/4#issuecomment-387353249

  • modifier key + key
  • modifier key + modifier key + key
  • modifier key + modifier key + modifier key + key

jaywcjlove avatar May 14 '18 01:05 jaywcjlove

Thank you. @jaywcjlove

xcv58 avatar May 14 '18 01:05 xcv58

Maybe the next stage supports this form:

key+key

E.g: h + m

jaywcjlove avatar May 14 '18 01:05 jaywcjlove

What is the status on this? (If you're working on it and probably done soon, your library will be great for me. Otherwise, I guess I could hack it together by activating a scope ^^ )

lucidBrot avatar Jul 22 '18 09:07 lucidBrot

@lucidBrot This is an enhancement. Have time or interest to implement this new feature.

jaywcjlove avatar Jul 22 '18 10:07 jaywcjlove

I've done something, which fits my needs, built upon your work: https://github.com/lucidBrot/Brotkeys.js
I thought I'd rather push it as its own repo, so that it won't contaminate your code for the people who don't need it. If you happen to look at it, let me know what you think :)

lucidBrot avatar Jul 28 '18 19:07 lucidBrot

@lucidBrot 👍

jaywcjlove avatar Jul 28 '18 19:07 jaywcjlove

@jaywcjlove so am I understanding that hotkeys does not support sequences?

This is a super useful feature that should definitely belong in the main branch of hotkeys! In fact I came to hotkeys from https://github.com/dmauro/Keypress just now specifically because https://github.com/dmauro/Keypress does support sequences but there's a bad bug and it's basically broken

And now I'm learning that this actively developed and maintained keyboard input project also doesn't support sequences... darn...

and @lucidBrot even made the feature already... why not merge it? Any plans to add key sequences to hotkeys @jaywcjlove ? would be awesome if you did..

vesper8 avatar Mar 24 '20 21:03 vesper8

@vesper8 You should be able to use my code easily in addition to hotkeys. I have not modified jay's hotkeys code but instead only depend on it.

Have a look at my readme and please also check out the issues before you commit to it.

lucidBrot avatar Mar 25 '20 05:03 lucidBrot

Just adding my plus here.

I'm also trying to migrate away from Mousetrap and this is, in my opinion, a useful feature to have. For me a requirement to finish the migration.

Taulim avatar Jul 13 '20 11:07 Taulim

Has anybody ever been able to implement key sequences as described by the original poster now 3 years ago when this feature request was created?

sebastienbarre avatar Jun 13 '21 00:06 sebastienbarre

@sebastienbarre yes I have, see https://github.com/jaywcjlove/hotkeys/issues/26#issuecomment-408629192 and https://eric.mink.li/publications/brotkeys_quickstart.html

the main page of my website uses it to add vimium-like functionality when you press F for a demo.

However, I haven't touched the code since then

lucidBrot avatar Jun 13 '21 13:06 lucidBrot

I've made an example with “chords” based on hotkeys scopes: https://codepen.io/mikkelricky/pen/vYZrqYJ

Without too much work it should be possible to write a function, hotkeysChord, say, that can do this automatically using the syntax mentioned in https://github.com/jaywcjlove/hotkeys/issues/26#issuecomment-388668433, i.e. something like

hotkeysChord('g,ctrl+a a,i,g', …)

mikkelricky avatar Sep 22 '21 09:09 mikkelricky