Skip to content

Instantly share code, notes, and snippets.

@stringparser
Created October 26, 2014 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stringparser/e34270628114d371f045 to your computer and use it in GitHub Desktop.
Save stringparser/e34270628114d371f045 to your computer and use it in GitHub Desktop.
document.addEventListener('keydown', function(e){ /* do stuff */ })
var util = { };
document.addEventListener('keydown', function(e){
var key = util.key[e.which];
if( key ){
e.preventDefault();
}
if( key === 'F1' ){
// do stuff
}
})
util.key = {
9: "tab",
13: "enter",
16: "shift",
18: "alt",
27: "esc",
33: "rePag",
34: "avPag",
35: "end",
36: "home",
37: "left",
38: "up",
39: "right",
40: "down",
112: "F1",
113: "F2",
114: "F3",
115: "F4",
116: "F5",
117: "F6",
118: "F7",
119: "F8",
120: "F9",
121: "F10",
122: "F11",
123: "F12"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment