whenipress
whenipress copied to clipboard
Sequential key support
I've been thinking about adding sequential key support to whenipress
.
The idea is that instead of registering a keyboard combo, you register a set of key presses that must be pressed in order. The syntax would look something like this:
whenipress('a', 'b', 'c', 'd', 'e', 'f', 'g').sequentially().then(e => alert('You know the start of the alphabet!'));
My issue is I don't know how widely used this would be, and I don't want to bloat the package with unused features as I'd like it to remain as small as possible. I did think of releasing it as a plugin that works alongside whenipress. Any thoughts or ideas are appreciated.
I would propose to make the syntax more group
like - so it would be:
whenipress().sequence('a', 'b', 'c').then(e => alert('First three letters of the alphabet pressed sequentially'));
But from my experience I never saw a use-case for this. 🤷
It would be handy for the Konami Code :-)
@millette But how many times did you implement the Konami Code onto a website ? I sadly never had the chance to.
@jkonze Once, that I remember. It was for a special feature I was ready to announce publicly, but it had great effect when I gave a presentation and launched (manually) the feature :-) True story!
The more I think about this, the more I think it would fit 'plugin' territory better
Another use-case for sequences is something like gmail and it's support for "g i" meaning "Go to Inbox". It supports other sequences, that's just the first that comes to mind.
P.S.: I'm not insisting for the feature, just laying out a few usage examples.
I've played around with the plugin way of implementing it.
Shouldn't be too difficult - though I wasn't able to make it work 💯% of the time due to issues with 2nd layer characters ( /
on my keyboard for example).
This would be a great feature. It is the one lacking feature that prevented me from using it.
It's not the most beautiful thing to do, but by nesting whenipress
you can create sequences.
@DionPotkamp would you have a code example to show what you mean?
Sure!
It's acting weird if you don't add the .once()
's. The first whenipress
shouldn't have the .once()
.
whenipress('a').then(e =>
whenipress('d').then(e =>
whenipress('m').then(e =>
whenipress('i').then(e =>
whenipress('n').then(e =>
console.log("admin!")
).once()
).once()
).once()
).once()
)