Skip to content

Instantly share code, notes, and snippets.

@amitmerchant1990
Last active August 29, 2015 13:56
Show Gist options
  • Save amitmerchant1990/8802009 to your computer and use it in GitHub Desktop.
Save amitmerchant1990/8802009 to your computer and use it in GitHub Desktop.
IMPLEMENT KEYBOARD SHORTCUTS FOR YOUR WEBSITE
$(document).ready(function() {
// I have used $(this) so it "listens" on any part of the webpage (document)
// Change this to a single or series of elements if required
$(this).live("keyup", function(e) {
if($("input, textarea").is(":focus")) {
// Do nothing because the user might be typing
return false;
} else {
switch(e.keyCode) {
case 65:
// Do something here when I press the A key
break;
case 69:
// Do something here when I press the E key
break;
// etc......
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment