Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.