Created
January 6, 2014 15:56
-
-
Save unknownuser88/8284869 to your computer and use it in GitHub Desktop.
FIND THE KEYCODE OF KEYBOARD KEY PRESSED
This file contains hidden or 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
(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