Skip to content

Instantly share code, notes, and snippets.

@joeylin
Last active December 30, 2015 21:19
Show Gist options
  • Save joeylin/7886324 to your computer and use it in GitHub Desktop.
Save joeylin/7886324 to your computer and use it in GitHub Desktop.
common process to key event
// key name
var key_names = {
32: 'SPACE',
13: 'ENTER',
9: 'TAB',
8: 'BACKSPACE',
16: 'SHIFT',
17: 'CTRL',
18: 'ALT',
20: 'CAPS_LOCK',
144: 'NUM_LOCK',
145: 'SCROLL_LOCK',
37: 'LEFT',
38: 'UP',
39: 'RIGHT',
40: 'DOWN',
33: 'PAGE_UP',
34: 'PAGE_DOWN',
36: 'HOME',
35: 'END',
45: 'INSERT',
46: 'DELETE',
27: 'ESCAPE',
19: 'PAUSE',
222: "'"
};
// get key
var key = e.keyCode || e.which;
// detect right click
var rightclick = (e.which) ? (e.which == 3) : (e.button == 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment