jwerty
Awesome handling of keyboard events
http://keithamus.github.io/jwerty/
jwerty is a JS lib which allows you to bind, fire and assert key combination strings against elements and events. It normalises the poor std api into something easy to use and clear.
jwerty is a small library, weighing in at around 1.5kb bytes minified and gzipped (~3kb minified). jwerty has no dependencies, but is compatible with jQuery, Zepto, Ender or CanJS if you include those packages alongside it. You can install jwerty via npm (for use with Ender) or Bower.
For detailed docs, please read the README-DETAILED.md file.
The Short version
Use jwerty.key
to bind your callback to a key combo (global shortcuts)
jwerty;jwerty;
Specify optional keys:
jwerty;
or key sequences:
jwerty;
You can also (since 0.3) specify regex-like ranges:
jwerty; // fires for ctrl+a,ctrl+b or ctrl+c
Pass in a context to bind your callback:
jwerty;
Pass in a selector to bind a shortcut local to that element:
jwerty;
Pass in a selector's context, similar to jQuery's $('selector', 'scope'):
jwerty;
If you're binding to a selector and don't need the context, you can ommit it:
jwerty;
Calls to jwerty.key
return a subscription handle that you can use to disconnect the callback
var h = jwertyh
Use jwerty.event
as a decorator, to bind events your own way:
;
Use jwerty.is
to check a keyCombo against a keyboard event:
{ if jwerty ... }
Or use jwerty.fire
to send keyboard events to other places:
jwerty;