36

USB keyboards must have been one of the first devices that could be connected to a USB port.

When you are from the US it's possible that you have never faced this problem. But in all other parts of the world you have to select your keyboard layout in the OS. Otherwise it is possible for example that you press 'z' and get 'y' (on German keyboards).

It's obvious that the keyboard could automatically tell the PC its layout. But for some reason such a function has never been part of the standard. Did they forget to add such a function?

16
  • 4
    USB 1.0 may be pretty old (IIRC it was designed in 1997), but USB is otherwise current technology. Is this still retrocomputing? Dec 6, 2022 at 17:36
  • 4
    The relevant standard (Device Class Definition for HID, v1.11) was last updated in 2001, so I think this is OK. The HID Usage Tables are constantly updated but they don’t add core features. Dec 6, 2022 at 19:15
  • 8
    @user3840170 You're right, USB as technology is by no way Retrocomputing, No matter what level. Though, I would classify this rather as a historical question, as it asks for some design choice way back in time, not about applying a still actual technology.
    – Raffzahn
    Dec 6, 2022 at 23:02
  • 3
    @zomega No, time allone doesn't make it on topic - especially not as all newer levels are still fully compatible. Even most modern controllers contain fall back hardware supporting the first spec.
    – Raffzahn
    Dec 6, 2022 at 23:03
  • 3
    Not worth a whole answer, but the absence of this function is obvious to anyone using more than one keyboard layout. A lot of languages have more than one layout (my native has 3 competing layouts, thank you very much, Microsoft), one generally needs to type basic Latin letters anyway and a lot of people generally blind-type on a basic qwerty keyboard.
    – fraxinus
    Dec 7, 2022 at 11:38

8 Answers 8

51

They didn’t forget to add such a function, they chose not to add one. The HID Usage Tables explain this as follows (section 10, page 88):

Note: A general note on Usages and languages: Due to the variation of keyboards from language to language, it is not feasible to specify exact key mappings for every language. Where this list is not specific for a key function in a language, the closest equivalent key position should be used, so that a keyboard may be modified for a different language by simply printing different keycaps. One example is the Y key on a North American keyboard. In Germany this is typically Z. Rather than changing the keyboard firmware to put the Z Usage into that place in the descriptor list, the vendor should use the Y Usage on both the North American and German keyboards. This continues to be the existing practice in the industry, in order to minimize the number of changes to the electronics to accommodate other languages.

Basically, keyboards don’t encode their layout so that manufacturers can change layouts only by swapping keycaps (for layouts with the same number of keys and same physical template).

5
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Chenmunka
    Dec 7, 2022 at 15:44
  • 21
    It's not just manufacturers, also users. I regularly switch my keyboard layout when I use a different language, typing letters which are not printed on the keyboard. Dec 7, 2022 at 22:58
  • 1
    This wouldn't make sense anyway: the layouts not only mix Latin letters, they may also change sets of letters e.g. to Cyrillic or kana, which would require addition of corresponding Usages.
    – Ruslan
    Dec 8, 2022 at 8:46
  • 1
    I understand the motivation behind OPs question. The issue by OP mostly affects people using non-US keyboards. I have to go through "layout hell," e.g., when using remote desktop because the client computers all have different keyboard layouts. Unfortunately, this is a major problem only for those using non-US keyboards; so any push to solve this problem must come from EU or others, who sadly do not seem to have sufficient influence on global hardware and software designs :( Also, majority of us don't tinker with our keyboards and use it as is. Dec 8, 2022 at 9:03
  • 5
    @AravindhKrishnamoorthy: That's a problem with the design of your remote desktop software -- it should allow forwarding either characters or scan codes, at the user's option.
    – Ben Voigt
    Dec 8, 2022 at 15:58
21

No, they did not forget it.

The HID descriptor does include a bCountryCode field, so it is in the specification, but it is not used for keyboard layout indication.

Keyboards may use it to indicate the localization based on country.

It is just not required and indicating non-localized is allowed for all keyboards.

All keyboards send the same codes for buttons in the same location. This is how it worked even before USB keyboards.

This simply allows the same keyboard hardware to just have different keycaps for different localizations and layouts.

This means it is also not required to have any customized HID descriptor programming needed to keyboard chips, so it is just a matter of building the keyboard with the right keycaps.

So on a German keyboard, the Z button sends exactly the same key code as a US keyboard with the Y button.

This also enables just switching the localization to another type, so even if the keycaps do not match, you can still use a foreign keyboard hardware with your PC with your native layout.

I think the motivation to leave the layout off is that there are countries with many languages and layouts. Many people also speak multiple languages. It would be near impossible to bring in new layouts to USB standards when something changes or updates.

And it would be just as annoying to plug in a keyboard with layout X and select layout X by default, even if you want to use layout Y because it is your native layout.

13
  • 5
    As I understand it, bCountryCode isn’t intended to reflect the keyboard layout, but the language of the keycaps themselves (e.g. “Shift” or “Maj” etc.). The supported values aren’t granular enough to uniquely describe keyboard layouts. Dec 6, 2022 at 18:36
  • 1
    @StephenKitt You are right - the bCountryCode was not for defining the actual layout, just for identifying the country code of localized hardware.
    – Justme
    Dec 6, 2022 at 18:46
  • I have two questions: 1. Is the string "bCountryCode" only used by Linux lsusb? 2. When I run a Linux live Image, why doesn't it automatically use German key mappings?
    – zomega
    Dec 6, 2022 at 20:25
  • Is there any means via which an input device can indicate that the user has entered a code which should be treated as "Z" without a particular key code, regardless of localization?
    – supercat
    Dec 6, 2022 at 21:34
  • 1
    @zomega Like I edited, bCountryCode can't be used to detect if you have German or any other layout. Linux live image can't know your keyboard layout so it does not know which layout it should use, so it just uses whatever is the default and the default is US layout. Even if keyboard sets country is German, no OS will likely use that information to set the layout. Which is good, since I would hate if I would plug in a random keyboard and it uses some random layout I could not care less, instead of the one I have already selected.
    – Justme
    Dec 6, 2022 at 22:56
18

As a historical side note and an extension to Stephen's Answer, a few historical notes may be helpful:

  • As seen in the citation, it was 'to minimize the number of changes to the electronics' more exactly

    • cost reduction by scale and as well,
    • not changing existing production process.
  • One side effect of the PC keyboard with its location addressing and handling of location to character/function handling on the host side was that, unlike earlier machines (*1), keyboards for different countries only differed in the keycaps put on top of common hardware

    • Keyboards could be produced in great numbers
    • Maximum number for each and every component (including mask-programmed controllers)
    • No low-volume parts needed for small markets
    • Only in the end, when keycaps were put on top (*2), did they become country-specific
    • Keycaps could be even exchanged in the field for very low volume countries.
  • Manufacturers wanted to stay with that model. Adding even a single country-specific identifier would have meant having

    • either different controllers, one per country, or
    • additional external components (switches, cuttable traces, etc.) and
    • different handling way before the keycaps were attached.
  • Around 1997 I worked in a project with Microsoft (one of their team members was (some time before) involved in USB definition and I learned about the effort Microsoft made to push exactly such an identifier). A HID descriptor for this was added, but it was not supported by any keyboard manufacturer.

  • Microsoft still went ahead to support auto detection, except, to keep compatibility with the quirk introduced by unwilling manufacturers, their keyboards had to report US-KBD in the default descriptor. To make it happen, a set of manufacturer-specific descriptors was added. As a result, some later 1990s Microsoft keyboards have their layout auto-detectable.


*1 - Classic terminals and many non-PC computers had either switchable keyboards that produced different codes, depending on country setting, or had to have different decoder chips, to serve different markets.

In fact, character generators (think National MM42xx) and keyboard decoders (NSC MM57xx or GI AY-5-3600, as used in Apple II) were the first major applications of large-scale ROM production.

*2 - Or marked by laser. The Siemens terminal plant, which was also making PCs, started (around 1990) to produce keyboards with only blanks to be later marked by laser according to whatever keyboard version the customer ordered. So it wasn't just a saving for Asian manufacturers using quick hands to press in keycaps to order.

4
  • How adversely would manufacturing efficiency have been affected by having to use a breakaway, punch-out, or other such means to select a keyboard layout when keycaps are installed on high-volume units, or ask a controller to program flash or EEPROM for more specialized ones? I would think being able to order a keyboard with a custom layout, that could be plugged in and simply work with its new layout, would be much more useful than having to configure a custom keyboard driver for every custom layout.
    – supercat
    Dec 8, 2022 at 18:41
  • custom? one customisable keyboard driver supports every layout.
    – Jasen
    Dec 9, 2022 at 8:33
  • @Jasen: Even if one has a driver that is configurable for arbitrary keyboard layouts, requiring manual configuration would still be a severe nuisance, especially if access to the configuration would require typing a password at a time when the computer isn't yet configured for the proper keyboard layout.
    – supercat
    Dec 9, 2022 at 19:01
  • keyboard layout is "settings" whether that is from OS or user provided config files. it's not software than need to be rewriten a hundered times.
    – Jasen
    Dec 9, 2022 at 20:29
13

It's obvious that the keyboard could automatically tell the PC its layout.

In 2005 I was unlucky enough to work on a Solaris system at a university computer lab in Sweden. Normally, I don't care what's printed on the keyboard. US QWERTY, some other type of QWERTY, AZERTY, QWERTZ — the first thing I do when I have a new login somewhere is to go to the settings and change the layout to Dvorak, because I touch type anyway.

Oh the horror. I was unable to do so on this Solaris. The keyboard informed the OS of its layout — changing it was not possible.

I don't think it was USB. I don't think it was PS/2 either. It was a Solaris keyboard attached to a Solaris computer, probably with a Solaris connector.

I don't remember what I used the computer for that day, but I remember my frustration of being stuck with a keyboard layout I did not choose or prefer. Thank you, USB consortium, for not enabling such behaviour on modern systems.

8
  • 5
    Just because the keyboard can inform the computer what layout it is meant for doesn't mean the OS couldn't override that by mapping it to a different one. Seems like a design flaw with Solaris, not with keyboards knowing their own layouts. Dec 7, 2022 at 19:38
  • 4
    Most likely a Type 6, or prior (4 or 5), Sun keyboard, which used a proprietory cable/connector. See also Sun Microsystems Keyboard - Type 6 vs Type 7, where someone also wants to use a Type 6 for Dvorak (but on Windows). Also, should the situation ever arise again, see How to change the Keyboard layout on Solaris Dec 8, 2022 at 0:02
  • 1
    @RadvylfPrograms I don't know if it was impossible by design, impossible by a bug, or impossible by sysadmin configuration for a mere user to change their own layout; I just remember trying and failing, and asking the IT support who told me it was not possible. It was 17 years, so forgive me for not remembering any more details :)
    – gerrit
    Dec 8, 2022 at 7:18
  • 1
    Amen to that, brother. Except, I use Neo2 instead of Dvorak. But typing on a standard layout is always pain if you are used to a good layout like Neo2 or Dvorak. In the end, a keyboard is just an array of keys, and it's the sane choice to let the user decide how characters are mapped onto these keys. Dec 8, 2022 at 23:27
  • @Greenonline SFAIK xmodmap did not require any special permissions, (but obviously that won't help if you're using the console in text mode).
    – Jasen
    Dec 9, 2022 at 8:40
4

In addition to other good answers here, consider the following. At the time of the first USB keyboards, it wasn't a given that Unicode would come to dominate character encodings. So we'd need to adopt or invent a way of describing the characters on each key. Not only that, but to cope with the different input methods in use, we'd need to represent group shifts, dead keys, compositions and the rest. Trying to get all the interested parties in agreement on the representation would delay the adoption by years, and likely stall the uptake of USB altogether.

Skipping this feature allowed vendors to quickly and cheaply adapt existing keyboards to the new interface, and that was essential to get any traction with users.

3

In addition to the other good answers note that there are keyboards with multiple language layouts printed on them. That would require an awkward switch on the keyboard if the keyboard decided the language - instead of the computer.

E.g., I have a Swedish keyboard - but the keys also have indications for Danish and Norwegian layout; something like https://www.corsair.com/eu/en/Categories/Products/Gaming-Keyboards/RGB-Mechanical-Gaming-Keyboards/k95-rgb-platinum-config/p/CH-9127014-ND (I guess it is cheaper than having 3 different products and such products have at least existed for a few years - even though I don't recall if they are retro yet). So, not even changing keycaps.

7
  • 2
    Come on that's just another excuse! A key combination could simply switch the layout. No need for a switch!
    – zomega
    Dec 8, 2022 at 16:32
  • @zomega: Indeed, if the layout switching were accomplished in the keyboard, there would be no need to worry about whether the host was aware of any layout which matched the printed legends.
    – supercat
    Dec 8, 2022 at 17:07
  • Yes, that is the case for all newer keyboards (some vendors call it "Nordic" layout). But it is a recent development (for some definition of "recent"); it wasn't always like that. My Logitech K260 (long retired for mechanical keyboards) has it, but not Logitech "Easycall Desktop" (also long retired, serving as dust covers for other keyboards...). Dec 8, 2022 at 18:02
  • BTW, I can't tell whether your reference to "an awkward switch" is real or sarcasm, given that many keyboards in the days before installable keyboard drivers included switches to change layout options, and such switches imposed far less hassle than having to open up driver settings.
    – supercat
    Dec 8, 2022 at 18:06
  • @supercat: Some newer ones have it for slight variation of location of keys (e.g., the Windows key). The Ducky I am typing on right now has its DIP switches (page 25) set different from the default (location of the "context" key (close to the right hand Ctrl key), etc.) Dec 8, 2022 at 18:08
1

There are a small number of physical keyboard layouts, that is keys in different arrangements. When my operating system detects a keyboard that is doesn't know, it asks the user to press the key to the left of the space bar. If you do that, it will know which physical keyboard you have. There are keyboards with or without arrow keys and numerical keypad; that's no problem, if you don't have these keys it is as if you never pressed them.

When you press a physical key, a code identifying that key is sent to the computer. That code will be the same, no matter what language you are using. For example pressing Z on a German keyboard or Y on an English keyboard, both users actually press the same key and the same code is sent.

The OS will have a translation table that translates key codes into letters. It will have different translation tables for different countries, and the user will choose the country. Usually a developer can read the key code (for example when writing a game played with the keyboard, there it's the physical keys that count), and what letters are produced - that can be quite complicated, for example some letters are produced by pressing two or more keys in a row.

Sometimes there are different translation tables for the same country - for example, Mac UK keyboards and PC UK keyboards have different letters printed on the keys, and you need to select the right translation table so that the letters on the keys match what you see on the screen (or if you type blind, you can just use the translation table that you are used to and don't care what's printed on the keys).

BTW. The USB standard allows you to specify a manufacturer and a model number. That's what you should do anyway. Now you just need someone to collect the information which manufacturer and model has which keys, and pray that nobody uses the same model number for different keyboards.

AND my Mac has a thing called "keyboard viewer" which is supposed to show the keyboard. It does not show the keyboard that I am using :-(

3
  • 1
    Manufacturers use the same model number for keyboards with different layouts. Dec 9, 2022 at 7:24
  • @StephenKitt Oh well. Why am I not surprised? Maybe in the case I noticed the OS knew "Manufacturer X model Y could be one of three keyboards, we ask the user to press the key left to the space bar and then we know which one it is".
    – gnasher729
    Dec 9, 2022 at 10:12
  • @gnasher729 The key left from space bar is different on Mac and PC keyboards. If you plug in a Windows keyboard to a Mac, it knows the button left of space is Alt button, and if you plug in a Mac keyboard, it knows the button left of space is not Alt. It just allows detection between a Mac and PC keyboard.
    – Justme
    Dec 9, 2022 at 23:52
-1

As far as I remember, plug and play came out later, and up to then nearly all devices had to be identified manually.

3
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Jan 5 at 16:19
  • 1
    Wrong. USB standard was released in 1996 and "Plug n Play" as a specific autoconfiguration mechanism for PCs was released before that in 1994. Before that many other autoconfiguration mechanisms have existed on other platforms years before PC platform got PnP support. Besides your answer does not explain why an USB keyboard has no way to tell the layout.
    – Justme
    Jan 5 at 17:21
  • 2
    General 'plug and play' support is orthogonal to the idea that one specific device, the keyboard, may or may not provide an indication of its configuration. Jan 5 at 23:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .