Key code
Also called KeyboardEvent.code · scan code
A key code identifies the physical position of a key, separate from the character it types. The same key reports the same code on a US layout and a French layout even though it types a different letter.
The keyboard test lights keys by code. If the right key lights up but the wrong letter appears in documents the keyboard is fine and the operating system layout is wrong.
In practice
A key code names a key’s position, such as KeyA for the key where A sits on a US keyboard. The character it types depends on the layout chosen in your operating system. That split is why a keyboard can be perfectly healthy and still type the wrong letters. The keyboard reports the right key and the operating system translates it with the wrong map.
How to check
Press the key that types the wrong character in the keyboard test. If the test lights the key in the position you pressed, the hardware is fine and the layout setting is wrong. Add or select the right layout in your language settings and remove ones you don’t use, since a keyboard shortcut can switch between them by accident.