Skip to content

Instantly share code, notes, and snippets.

@brianium
Created March 27, 2012 17:59
Show Gist options
  • Save brianium/2218442 to your computer and use it in GitHub Desktop.
Save brianium/2218442 to your computer and use it in GitHub Desktop.
meta example with key codes
var KeyMap = {
"Enter":13,
"Shift":16,
"Tab":9,
"LeftArrow":37
};
for (var key in KeyMap) {
KeyMap["is" + key] = function(compare,ev) {
return ev.keyCode == compare
}.bind(KeyMap,KeyMap[key]);
}
window.onkeyup = function(e) {
if(KeyMap.isEnter(e)) {
alert('its enter!');
} else {
alert(e.keyCode);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment