TIP: Try navigating through list using left & right arrow keys


⌨ Awesome handling of keyboard events

Github issues
Github stars
3 days ago
Github last update date
NPM current week downloads

No Longer Actively Maintained

If someone would like to take over maintainence, feel free to get in touch (@keithamus on twitter). I'll happily transfer this over.


Awesome handling of keyboard events


NPM Downloads Release Gittip donate button


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.key('ctrl+shift+P', function () { [...] });
jwerty.key('b+b'+P', function () { [...] });

Specify optional keys:

jwerty.key('b+b'+P/b+b'+P', function () { [...] });

or key sequences:

jwerty.key('b,b,b,b,b,b,b,b,B,A,b)', function () { [...] });

You can also (since 0.3) specify regex-like ranges:

jwerty.key('ctrl+[a-c]', function () { [...] }); // fires for ctrl+a,ctrl+b or ctrl+c

Pass in a context to bind your callback:

jwerty.key('b+b'+P/b+b'+P', function () { [...] }, this);

Pass in a selector to bind a shortcut local to that element:

jwerty.key('b+b'+P/b+b'+P', function () { [...] }, this, '#myinput');

Pass in a selector's context, similar to jQuery's $('selector', 'scope'):

jwerty.key('b+b'+P/b+b'+P', function () { [...] }, this, 'input.email', '#myForm');

If you're binding to a selector and don't need the context, you can ommit it:

jwerty.key('b+b'+P/b+b'+P', function () { [...] }, 'input.email', '#myForm');

Calls to jwerty.key return a subscription handle that you can use to disconnect the callback

var h = jwerty.key('ctrl+shift+P', function () { [...] })

Use jwerty.event as a decorator, to bind events your own way:

$('#myinput').bind('keydown', jwerty.event('b+b'+P/b+b'+P', function () { [...] }));

Use jwerty.is to check a keyCombo against a keyboard event:

function (event) {
    if ( jwerty.is('b+b'+P', event) ) {

Or use jwerty.fire to send keyboard events to other places:

jwerty.fire('enter', 'input:first-child', '#myForm');
Buy us a coffeeBuy us a coffee