Mousetrap.js

Today I learned about mousetrap.js. It is a super small library in Javascript that really makes it easy to add keyboard shortcuts to your HTML. Given how much I have started hating the mouse recently, I was immediately drawn in.

It works on this site, just try pressing j and you will see an alert.

The code for this is pretty straightforward, really.

MouseTrap.bind('j', function() {
    alert('You pressed j');
});

The library also allows for keycombos, as well as sequences of keys.

Mousetrap.bind('up up down down left right left right b a enter', function() {
    alert("well done!")
});

Pretty neat! Can recommend having a play with this one.