I need to figure out which character was typed into a text field from within the handler that is called by jQuery’s keydown function. key.which gives me only the keycode, but I need to figure out which ASCII character key represents. How do I do this?
I need to figure out which character was typed into a text field from
Share
For character input, it is suggested you use
keypress(), which will report the actual ASCII code for the character pressed. It automatically takes care of letter case, and ignores non-character presses. In either case, you can use fromCharCode() to convert to a string representation. E.g.Just remember that for
keydown()andkeyup(), you’ll have to keep track of the case using thee.shiftKeystate.