Skip to content

Instantly share code, notes, and snippets.

@bmoren
Created March 2, 2015 23:56
Show Gist options
  • Save bmoren/1c9968150644ca37db3d to your computer and use it in GitHub Desktop.
Save bmoren/1c9968150644ca37db3d to your computer and use it in GitHub Desktop.
Jquery Keypress Event
$(function(){ //jq do some work! - when ever the DOM is ready, do the stuff in here!
$(document).keypress(function(e) { // look at the keypressed
if(e.which == 97) { // use some logic to see what key was pressed
alert('You pressed "A"!'); //do something when that key was pressed
}
});
///////USE BELOW TO FIGURE OUT KEY NUMBERS!
$(document).keypress(function(e) {
console.log("keypressed: " + e.which);
});
}); // stop doing jquery sutff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment