Bind Keyboard Shortcuts in JavaScript with Mousetrap

Mousetrap is a lightweight (1.4kb minified and gzipped) standalone JavaScript library for handling keyboard shortcuts.

It has been tested in all common browsers and will also work in legacy browsers such as IE6.

It also supports special keys such as: shift, ctrl, alt, option, meta, command, backspace, tab, enter, return, capslock, esc, pageup, pagedown, end, home, left, up, right, down, and del.

Key presses are typically bound to a callback function using: Mousetrap.bind('/', _focusSearch); however the documentation provides more detailed guidance on using more advanced features such as key combinations and sequences.

Leave a Reply

Your email address will not be published. Required fields are marked *