You won't want to miss out on the world-class speakers at TNW Conference this year 🎟 Book your 2 for 1 tickets now! This offer ends on April 22 →

This article was published on July 9, 2012

This simple JavaScript library makes it easy to add keyboard shortcuts to your Web app


This simple JavaScript library makes it easy to add keyboard shortcuts to your Web app

For all the Web developers and designers out there, you’ll know that working with keyboard events isn’t a simple feat. So if you’ve ever desired to build shortcuts into your Web app, there’s a new and easy to use JavaScript library by the name of Mousetrap that can help.

Mousetrap is a simple and small (1.5kb) library for handling keyboard shortcuts without the use of jQuery and works in IE 6+, Safari, Firefox, Chrome and possibly Opera (so we’ve heard). To use it, simply call the Mousetrap.bind method, specify the key or combination of keys and then set what you want done. Even the beloved konami code can be used:

// konami code!
Mousetrap.bind(‘up up down down left right left right b a enter’, function() {
highlight([21, 22, 23]);
});

Those familiar with this space may also know of Keymaster, an older library which seems to have been unmaintained as of late. No matter what, both libraries are worth checking out, if only to know the choices available to you.

You can learn more about Mousetrap via the link below:

➤ Mousetrap

While you’re at it, you might also like ResponsiveSlides.js, “a simple & lightweight responsive slider plugin” for jQuery.

Get the TNW newsletter

Get the most important tech news in your inbox each week.