Skip to content

Instantly share code, notes, and snippets.

@stugoo
Last active December 19, 2015 04:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stugoo/5899808 to your computer and use it in GitHub Desktop.
Save stugoo/5899808 to your computer and use it in GitHub Desktop.
up down left right keycode events
document.addEventListener('keyup', function (e) {
var keyCode = e.keyCode || e.which,
arrow = { left: 37, up: 38, right: 39, down: 40 };
switch (keyCode) {
case arrow.left:
console.log(keyCode);
break;
case arrow.up:
console.log(keyCode);
break;
case arrow.right:
console.log(keyCode);
break;
case arrow.down:
console.log(keyCode);
break;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment