Skip to content

Instantly share code, notes, and snippets.

@yoko
Created March 26, 2010 22:21
Show Gist options
  • Save yoko/345477 to your computer and use it in GitHub Desktop.
Save yoko/345477 to your computer and use it in GitHub Desktop.
var shortcut = {
keys: [],
setup: function() {
document.addEventListener('keypress', this.keypress, false);
return this;
},
bind: function(key, handler) {
this.keys[key] = handler;
return this;
},
keypress: function(e) {
if (e.shiftKey || e.ctrlKey || e.altKey || e.metaKey) return;
var key = String.fromCharCode(e.which);
var handler = shortcut.keys[key];
if (handler) handler(e);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment