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(){
  console.log("Sequences!");
});

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

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

News Films

Our little film studio focuses on telling developer-centric stories that need to be seen.

Beyond Code: Season 3 / GopherCon 2015

 
0:00 / 0:00