I am currently working on a USB HID keyboard using an Atmel microcontroller.
Everything is working fine but I usually use different keyboard layouts on different machines.
Now I started wondering if it would be possible to tell the host which keyboard layout to use, i.e. EN-US, so that keycodes will always get mapped on the right character on every machine.
Any ideas?
krogerfeedback
Send language layout from USB HID keyboard
- vvp
- Main keyboard: Katy/K84CS
- Main mouse: symetric 5-buttons + wheel
- Favorite switch: Cherry MX
- DT Pro Member: -
Not without a a custom driver.
You can write some macro which will do it for you or an application which will switch the layout after some special input (e.g. on F13).
And you can use something like Compose key or Unicode hex input to simulate changing layouts.
Compose key support is native in linux and requires an application to get support on windows.
Unicode hex input should be supported by both windows and linux but there probably will be caveats. I did not really try it.
You can write some macro which will do it for you or an application which will switch the layout after some special input (e.g. on F13).
And you can use something like Compose key or Unicode hex input to simulate changing layouts.
Compose key support is native in linux and requires an application to get support on windows.
Unicode hex input should be supported by both windows and linux but there probably will be caveats. I did not really try it.
-
- Location: Stockholm, Sweden
- DT Pro Member: 0011
There is a "bCountryCode" field in the HID descriptor which is downloaded from the keyboard to the host when the keyboard is connected, but I believe that it is unsupported by operating systems because code the code space is badly defined and I think most keyboards are manufactured with their internals supporting multiple layouts (code 0: "Not supported") anyway.
You could perhaps put a USB hub inside the keyboard, with the keyboard and a USB stick under the hub. Then put a autorun.inf on the stick with a command to change the layout.
That would require the computers to run MS Windows, have autorun enabled and you would only be able to change to the one layout on the stick.
Although I suppose you could circumvent the latter by having multiple sticks and use a physical switch to power up only one at a time. (But that would really be a kludge)
Spoiler:
That would require the computers to run MS Windows, have autorun enabled and you would only be able to change to the one layout on the stick.
Although I suppose you could circumvent the latter by having multiple sticks and use a physical switch to power up only one at a time. (But that would really be a kludge)
- depletedvespene
- Location: Chile
- Main keyboard: IBM Model F122
- Main mouse: Logitech G700s
- Favorite switch: buckling spring
- DT Pro Member: 0224
- Contact:
... not that I mean to be a prick, but a keyboard with a program to run on the host when plugged onto it would be rejected anywhere with any sense of security (EVEN my former bank).
- AlbertoGP
- Location: Saarbrücken, Germany
- DT Pro Member: -
That’s right, I just tried with my Sun Type 7 keyboard in Linux, MacOS X, and Windows 10, and the selected layout does not change to the one reported by the keyboard when I plug it in.Findecanor wrote: ↑02 Jun 2019, 03:09There is a "bCountryCode" field in the HID descriptor which is downloaded from the keyboard to the host when the keyboard is connected, but I believe that it is unsupported by operating systems because code the code space is badly defined and I think most keyboards are manufactured with their internals supporting multiple layouts (code 0: "Not supported") anyway.
From the USB Device Class Definition for Human Interface Devices (HID) Firmware Specification Version 1.11, page 22 (32 in PDF):
https://usb.org/sites/default/files/doc ... _11.pdf#32
As far as I know, the only OS to use this is Sun’s Solaris. They believed in it so much that in their SPARC-based machines “You cannot change the layout of Type 6 keyboards because the back of the keyboard has no DIP switch. Some Type 5 and 5c keyboards, for example, U.S.A., U.S.A./UNIX, and Japanese keyboards have jumpers instead of DIP switches. Other than the xmodmap utility or the kbd -s command, the SPARC platform does not offer utilities or tools that you can use to switch keyboards.” [1]The value bCountryCode identifies which country the hardware is localized for. Most hardware is not localized and thus this value would be zero (0).
However, keyboards may use the field to indicate the language of the key caps.
Devices are not required to place a value other than zero in this field, but some operating environments may require this information. The following table specifies the valid country codes.
[1] https://docs.oracle.com/cd/E19253-01/81 ... index.html
-
- Location: UK
- Main keyboard: Planck
- Main mouse: Cyborg Rat 7
- Favorite switch: Alps skcm white
- DT Pro Member: -
I would say the best way to do it would be to use something like QMK firmware and have the different layouts that you want on different layers so you would be able to cycle to the layer that you want depending on the system you are in and with all programming done and remaining on the keyboard level.
-
- Location: Stockholm, Sweden
- DT Pro Member: 0011
The problem is that language-layout is interpreted by the host, not the keyboard.
I think that ultimately, the solution would have to be in host software.
Either make sure that you have to log in and have the layout changed in your login script.
Or make a script (for AutoHotKey or a USB device management program) that detects the particular VendorID/ProductID pair of your keyboard and changes the layout as a result.
- vvp
- Main keyboard: Katy/K84CS
- Main mouse: symetric 5-buttons + wheel
- Favorite switch: Cherry MX
- DT Pro Member: -
That is only a problem if one cannot get a generic super set of all layouts working. Like Compose key or unicode hex input. Then you can issue any key using the right tiny macro. Compose key(*) works fine on both windows and linux. I cannot comment much on unicode hex input since I did not use it. There may be other usable options.Findecanor wrote: ↑04 Jun 2019, 10:23The problem is that language-layout is interpreted by the host, not the keyboard.
(*) Compose key on windows requires installation of an additional program but it works well.
- depletedvespene
- Location: Chile
- Main keyboard: IBM Model F122
- Main mouse: Logitech G700s
- Favorite switch: buckling spring
- DT Pro Member: 0224
- Contact:
And that is another problem with requiring the usage of a language code hardcoded (so to speak) in the keyboard itself: it would restrict its usage to a certain list of pre-known national layouts, limiting the creation of others customized for a particular user's whims or for new languages, or even new takes on an existing language (not to even mention if things get political when it comes to the language itself). In the end, I think the current state of things (the keyboard sends codes corresponding to the physical layout and the operating systems translate them to the corresponding characters according to one of many conversion tables that it has on hand).
Of course, the physical layout could be improved, and many national layouts (as specified by those conversion tables) need serious updates, too, but that's another matter. I should know.
- swampangel
- Location: Canada
- Main keyboard: Northgate Omnikey 101
- DT Pro Member: -
Others have given you some advice on why this might not be a great idea. But I think it's possible, if your hosts all run the same OS at least:
https://h3llwings.wordpress.com/2016/10 ... th-teensy/
https://docs.microsoft.com/en-us/powers ... w=win10-ps
You'd be creating an exploit, more or less, to run powershell commands when you plug in or press a certain key combo. I imagine you could do the same for mac/linux too with different commands.