Join us at TNW Conference 2022 for insights into the future of tech →

The heart of tech

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
    Harrison Weber
    Story by

    Harrison Weber

    Harrison Weber is TNW's Features Editor in NYC. Part writer, part designer. Stay in touch: Twitter @harrisonweber, Google+ and Email. Harrison Weber is TNW's Features Editor in NYC. Part writer, part designer. Stay in touch: Twitter @harrisonweber, Google+ and Email.

    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.