Skip to content

Instantly share code, notes, and snippets.

@cneud
Created December 4, 2019 01:57
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 cneud/1804c11af67425cd6003c988ba4a8c39 to your computer and use it in GitHub Desktop.
Save cneud/1804c11af67425cd6003c988ba4a8c39 to your computer and use it in GitHub Desktop.
// jQuery arrow keys + escape key + enter key
$(document).keydown(function(e) {
switch(e.which) {
case 13: // enter
break;
case 27: // escape
break;
case 37: // left
break;
case 38: // up
break;
case 39: // right
break;
case 40: // down
break;
default: return; // exit this handler for other keys
}
e.preventDefault(); // prevent the default action (scroll / move caret)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment