Skip to content

Instantly share code, notes, and snippets.

@murtaugh
Last active August 29, 2015 13:57
Show Gist options
  • Save murtaugh/9924509 to your computer and use it in GitHub Desktop.
Save murtaugh/9924509 to your computer and use it in GitHub Desktop.
Keyboard Controls
document.onkeydown = checkKey;
function checkKey(e) {
e = e || window.event;
if ((e.keyCode == '39') || (e.keyCode == '40')) { // right / down arrow
console.log('right / down');
} else if ((e.keyCode == '37') || (e.keyCode == '38')) { // left / up arrow
console.log('left / up');
} else if (e.keyCode == '32') { // space bar
console.log('space');
} else if (e.keyCode == '27') { // esc key
console.log('esc');
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment