Last active
August 29, 2015 13:56
-
-
Save amitmerchant1990/8802009 to your computer and use it in GitHub Desktop.
IMPLEMENT KEYBOARD SHORTCUTS FOR YOUR WEBSITE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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