The Changelog

Open Source moves fast. Keep up.

Mousetrap.js – JavaScript Keyboard Shortcuts

Craig Campbell, who we covered in a previous article, has released a library for handling JavaScript keyboard shortcuts.

It is small (~2kb minified), has no external dependencies, and is very simple to use:

Mousetrap.bind("$", function(){
  console.log("Like a gentleman!");

It also has support for gmail-style sequences and key combinations:

Mousetrap.bind("g i", function(){

Mousetrap.bind("command+shift+k", function(){
  console.log("Key combinations!");

Checkout the examples to see some more features, or browse the source at GitHub.

Have comments? Send a tweet to @TheChangelog on Twitter.

Subscribe to The Changelog Weekly – our weekly email covering everything that hits our open source radar.