A keyboard does not transmit characters, like "a" or "b" nor ASCII numbers. It does transmit something like "key numbers" (scancodes). So the transmitted information is more like: key number 2 on row 4 was pressed (or released).
The only difference between a Danish a German or an US keyboard is the printing on the keys, but the hardware is completely the same.
The operating system on your computer with the language settings interpretes the information comming from the keyboard and "produces" the characters that appear on the screen.
So the example ("key 2 on row 4") would lead to the letter a on computers in the US, in Germany and Denmark (with appropriate language settings) because "a" is on the same spot.
Arduino Leonardo and Micro (ATmega32u4) use US keyboard layout.
There is no (easy) way to switch to an other language layout.
There are some workarounds. The one I prefer is using scancodes.
You can find the scancodes of an USB-Keyboard here (US layout): USB HID usage table (see #7 Keyboard).
For some reasons Arduino keyboard functions will treat values below 128 (0x7F) as "printable" so it will look them up in a table of ascii keycodes. This is not what you want. To get past that you have to add 136 (0x88) to the scancode.
To find out what scancode produces what letter (or F key and so on) with your language settings you can use a simple test sketch like this:
#include "Keyboard.h"
void setup() {
Keyboard.begin();
delay(7000); // to get you some time to switch to your editor
Keyboard.print("start");
Keyboard.write(KEY_RETURN);
for (int i = 0x04; i < 0x38; i++) {
int j = i + 0x88;
Keyboard.print("0x");
Keyboard.print(j, HEX);
Keyboard.print(" ");
Keyboard.write(j);
Keyboard.print(" ");
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.write(j);
Keyboard.releaseAll();
Keyboard.write(KEY_RETURN);
}
Keyboard.print("end");
}
void loop() {
}
This will "print" the result of several scan codes without and with the shift key pressed simultaneously.
A text editor should be active when running this code.
The scancodes can be used with Keyboard.write(nnn) and Keyboard.press(nnn).
An å on your Danish computer should appear with:
Keyboard.write(0xB7);
But I could not test this (with my German language settings). ![]()