keithamus / jwerty

⌨ Awesome handling of keyboard events
http://keithamus.github.io/jwerty
Other
1.21k stars 107 forks source link

Adding support for multiple combos syntax #42

Open nicholasrq opened 11 years ago

nicholasrq commented 11 years ago

I've added support for "multiple combos" as alternative of many combox separated by slash. You can now write

jwerty.is("cmd+[a,b,c]", event)
jwerty.is("cmd+shift+[a,b,c]", event)
jwerty.is("[ctrl, cmd]+a", event)

instead of

jwerty.is("cmd+a/cmd+b/cmd+c", event)
jwerty.is("cmd+shift+a/cmd+shift+b/cmd+shift+c", event)
jwerty.is("cmd+a/ctrl+a", event)

And next example demonstrates the power of new syntax.

Old style:

jwerty.is("backspace/backspace+ctrl/backspace+cmd/backspace+alt/delete/delete+ctrl/delete+cmd/delete+alt", event)

New style:

jwerty.is("backspace/backspace+[cmd,ctrl,alt]/delete/delete+[cmd,ctrl,alt]", event)

This syntax works like abbreviations and my code just expands it into full combo. Everything from old syntax (such as [a-z] or [0-9]) works as usual.

keithamus commented 11 years ago

I absolutely love the idea. I can't help but feel the code could be improved though. I'm going to look at this in more detail a bit later on.

nicholasrq commented 11 years ago

Ok, thanks. I'm glad to see that you're interested in my idea. I'll wait for your comments.