hotkeys-js
hotkeys-js copied to clipboard
Whether support Sequence of keys?
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:

https://craig.is/killing/mice
Could you please confirm whether this library supports the feature? Thanks!
@xcv58 I looked at it and there should be no problem with migration.
Great, thank you!
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?
I read the shortcuts in Gmail. This shortcut is not supported.

Currently supports multiple forms: https://github.com/jaywcjlove/react-hotkeys/issues/4#issuecomment-387353249
modifier key+keymodifier key+modifier key+keymodifier key+modifier key+modifier key+key
Thank you. @jaywcjlove
Maybe the next stage supports this form:
key+key
E.g: h + m
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 This is an enhancement. Have time or interest to implement this new feature.
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 👍
@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 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.
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.
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 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
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', …)