Skip to content

Instantly share code, notes, and snippets.

@unknownuser88
Created January 6, 2014 15:56
Show Gist options
  • Save unknownuser88/8284869 to your computer and use it in GitHub Desktop.
Save unknownuser88/8284869 to your computer and use it in GitHub Desktop.
FIND THE KEYCODE OF KEYBOARD KEY PRESSED
(function($) {
/* get key code */
function getKeyCode(key) {
//return the key code
return (key == null) ? event.keyCode : key.keyCode;
}
/* get key character */
function getKey(key) {
//return the key
return String.fromCharCode(getKeyCode(key)).toLowerCase();
}
$(document).ready(function() {
$(document).keydown(function(eventObj) {
/* display the key and character code for the key you pressed */
alert("Key pressed: " + getKey(eventObj) + " Code = " + getKeyCode(eventObj));
});
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment