Andrew Thorp changelog.com/posts

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.


Discussion

Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00