I have using iframe
in my application. I have return string value when i press any key from keyboard.
All other keys are returned expected string value except key 219 ,220, 221
.
These keys are returned "Û", "Û", "Ý"
these values.
But i'm expected "[", "]", "\"
these string values.
How can I get the correct character from those keys?
keydown
andkeyup
use keycodes that can vary from keyboard to keyboard depending on your input keyboard type (different keyboards for different regions, etc.).For printable characters, you need to wait for the browser to issue
keypress
, which gives you the translated value of the key to character (if there is one), which it gives you incharCode
(although paranoically I tend to doe.charCode || e.which
; maybe that's silly). For instance, there's a key on my keyboard that, under *nix the way I have it configured, is keycode 220 forkeydown
/keyup
and generates the character£
. But in a virtual machine running Windows with a different keyboard layout, that same key is keycode 220 forkeydown
/keyup
but generates the character#
.Example: