Difference between Event.key and Event.code

Asked

Viewed 53 times

0

I’d like to know the difference between event.key and event.code.

1 answer

0


Hello,

event.key represents the value of the key pressed by the user, taking into account the state of the modifier keys, for example: Shift, as well as the location and layout of the keyboard.

event.code represents a physical key on the keyboard (as opposed to the character generated by pressing the key). In other words, this property returns a value that is not changed by the keyboard layout or by the state of the modifier keys.

Here is a code with example that displays the two values: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code

Browser other questions tagged

You are not signed in. Login or sign up in order to post.