Created
March 27, 2012 17:59
-
-
Save brianium/2218442 to your computer and use it in GitHub Desktop.
meta example with key codes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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