Possible duplicate:
Get the correct key code for keyboard keys (numpad)
I am writing an application that should be able to get the value of numbers pressed on the keyboard. I came up with the following code:
var keyVal = ""; $(document).on("keydown.xRuleKey", function(e) { var keyChar = String.fromCharCode(e.which); if (!isNaN(keyChar)) { keyVal += keyChar; } })
This works great for numbers at the top of the keyboard, but when I use numpad, the characters “abcdefghi” are returned instead of “0123456789”. Is it ordinary or is my keyboard weird? If this is normal, it’s safe to just set a key / value pair to translate the letter to this number equally likely or contrary to anything else. I don’t think it will conflict with ordinary letters, as they return uppercase characters, and numpad in lowercase.
Any thoughts? Has anyone dealt with this before?
source share