Using e.keyCode || e.which; how to determine the difference between lowercase and uppercase?

后端 未结 5 1952
星月不相逢
星月不相逢 2020-12-20 20:32

I am using e.keyCode || e.which; to determine which key was pressed, but I am getting 65 for both a and A why is this happening and ho

5条回答
  •  庸人自扰
    2020-12-20 21:13

    Whether it's 'a' or 'A', 65 is the result of the key pressed on the keyboard and it's always 65 for that key.

    The event will only specify which key is pressed and not its value; those are two separate things. You can test for event.shiftKey along with the key that you're looking for, but I don't believe that will handle the scenario where Caps Lock is enabled.

提交回复
热议问题