keithamus / jwerty

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

sends key history to triggered function #68

Open 2x2xplz opened 8 years ago

2x2xplz commented 8 years ago

Tracks key press history and adds a keySequence object to the final event (which is already sent to triggered function). Useful when using multiple-choice or regex-like syntax. i.e. get the actual 3-digit code that triggered shift+;,[0-9],[0-9],[0-9]. keySequence is an object that contains an object per key press, and also a string representation called sequence using pipes to separate keys: shift+h|e|l|l|o|space|ctrl+w|o|r|l|d

example usage:

jwerty.key('ctrl+shift+;,[a-e],[f-j],[k-o]' , function() { 
  alert(this.event.keySequence.sequence); 
});

jwerty has tremendous potential because of regex support, which other libraries do not have. However its overall support for sequences is spotty, for example, (on Chrome 51/Windows at least) sequences which end in a modifier like a,b,shift+c do not trigger. Some regex edge cases are also unsupported: [a-z],[a-z],[a-z],enter will not be triggered by abcd-enter (I would expect bcd-enter to be the match). Still, the support it does have is great and along with ajax requests, allows for simple password-type sequences that can't be revealed with View Source. I really hope you'll revisit this library and finish 0.4. Thanks.

wadestuart commented 7 years ago

+1 for this type of functionality -- I also have had to fork out to create something similar but some core support for exposing the captures that exercised the event just makes sense given the regex functionality.

Not sure I think the stringified result in this patch is the best option but given a choice between this or nothing this is better. =)