Issue with javascript onkeydown - event.which give characters in upper case only

前端 未结 4 422
北荒
北荒 2021-01-14 04:15

I have written a piece of javascript code to get the key pressed within a text area. I have used the onkeydown event to capture the key pressed and am calling a function whe

4条回答
  •  时光说笑
    2021-01-14 04:25

    The issue is that keydown event will report keypresses - that is, physical keys pressed. The keypress event will report the translated keys, meaning the character that has been derived from the keys pressed (Shift + a == A). In order to get the actual keys, you may need to keep track of both keydown/keyup (to monitor the modifier keys) and keypress (to monitor the actual alphanumeric user input.)

提交回复
热议问题