Robin Hartley
Robin Hartley

Reputation: 101

How does one keyboard press lead to different characters, depending on layout

Thank you for taking the time to look at this question.

If you press the ‘y’ key on a keyboard, it is my understanding, that a UTF-8 keycode is sent over USB corresponding to the ‘y’ key. i.e. 0x79 in hex.

This is then interpreted by the computer as the letter ‘y’ and sent to the active window as a keystroke.

My question is, how come when you plug a US keyboard into a German computer, pressing the ‘y’ key results in the letter ‘z’ being sent to the active window.

Now on German keyboards, the letter ‘z’ is in the position which the ‘y’ key is in on a US keyboard. However, if each character has a unique UTF-8 code associated with it, surely pressing the ‘y’ key will generate the ‘y’ keycode (0x79) and this will be interpreted as a ‘y’ by the computer. Surely the location of that key on the keyboard shouldn't matter?

I assume there must be interconversion at some point to account for different layouts. How and at what point does this interconversion happen, is it done by the microcontroller in the keyboard or by the computer when it receives the keycode?

Please feel free to point out any wider misunderstandings in the above questions if they are present.

Many thanks for your time.

Upvotes: 0

Views: 292

Answers (1)

devdob
devdob

Reputation: 1504

There are a couple of things your computer is aware of, first is your keyboard layout, which is usually asked about (in Ubuntu during installation for example) or detected automatically (like in Windows for example) by the default keyboard driver. The second is the system language, or preferred language, or keyboard language depending what its called in your Operating System.

When you plug in your English keyboard, the system recognizes it as an English keyboard and will look for your selected language and map the keys accordingly. I type in both English and Arabic, the keyboard layouts are totally different, and all I do is choose from the my keyboard icon in the taskbar that i want to type in Arabic now, the system still uses my English keyboard but with an Arabic keymap.

Hope this explains it!

Upvotes: 1

Related Questions