1

The Keyboard API allows the Arduino boards such as the Micro or Leonardo to emit USB signals mimicking a physical keyboard. However, the signal seems to transmit key strokes and not characters which means that machines with different region settings interpret the USB signal differently. For example, a y will be interpreted as z in a German OS since the keyboard layout has these keys swapped.

Is there any way to output a signal that will result in the correct character being transmitted regardless of the OS settings without any modifications to the machine the Arduino is attached to?

2
  • 1
    @jsotola AFAIK most keyboards send the pressed physical key and not the character represented by that key. However I have heard about attempts to allow a keyboard to specify its layout and haven't found any further resources on this.
    – Philipp
    Feb 11, 2019 at 22:08
  • stumbled across this today ........ github.com/NicoHood/HID/blob/master/src/HID-Settings.h
    – jsotola
    Feb 14, 2019 at 6:41

2 Answers 2

3

No. There is no such facility.

If you take a German keyboard and plug it into a US configured computer the key layout will be wrong. You have to tell the computer that you're using a German keyboard.

Keyboards don't know what is printed on the keycaps. All they understand is where the buttons are physically located.

The same with the Arduino. It's sending the keypresses that correspond to the keyboard layout of a US keyboard, and you have to tell the computer that you're using a US keyboard - because that is effectively what you are using.

If you want to change the keyboard map the Arduino uses you will have to manually modify the Keyboard library (file Keyboard.cpp, array _asciimap[128]).

3

Download Device Class Definition for Human Interface Devices (HID)

https://www.usb.org/sites/default/files/documents/hid1_11.pdf

See section 6.2.1 HID Descriptor

bCountryCode 0x09 German

also see section E.4 (page 67)

E.4 HID Descriptor (Keyboard)
Part            Offset/Size  Description                                         Sample
                (Bytes)                                                          Value
----------------------------------------------------------------------------------------
bLength           0/1        Size of this descriptor in bytes.                    0x09
bDescriptorType   1/1        HID descriptor type (assigned by USB).               0x21
bcdHID            2/2        HID Class Specification release number
                             in binarycoded decimal—for example, 2.10 is 0x210).  0x101
bCountryCode      4/1        Hardware target country.                             0x00
bNumDescriptors   5/1        Number of HID class descriptors to follow.           0x01
bDescriptorType   6/1        Report descriptor type.                              0x22
wDescriptorLength 7/2        Total length of Report descriptor.                   0x3F
1
  • 1
    That field is ignored by all operating systems. It was intended to be used, but no one does. Keyboard manufacturers didn't want to have to create separate controllers for each and every language of keyboard - it is so much cheaper to just have one and change what's printed on the keyboard. Also I know of no operating system that can apply keymaps to individual inputs - it's only set on the user session as an entirety. All inputs are amalgamated first and then mapped from key codes to characters afterwards.
    – Majenko
    Feb 12, 2019 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.