Skip to content

Instantly share code, notes, and snippets.

@Stoffo
Last active October 29, 2015 15:11
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 Stoffo/88fb3d584444a10a4b42 to your computer and use it in GitHub Desktop.
Save Stoffo/88fb3d584444a10a4b42 to your computer and use it in GitHub Desktop.
simple event handler to map keycodes of arrow keys to functions.
$(window).on('keyup', function (e) {
switch (e.keyCode) {
/*left*/
case 37:
console.log('left');
break;
/*right*/
case 39:
console.log('right');
break;
/*up*/
case 38:
console.log('up');
break;
/*down*/
case 40:
console.log('down');
break;
/*escape*/
case 27:
console.log('escape');
break;
/*enter*/
case 13:
console.log('enter');
break;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment