I am creating a keyboard and the PC I use it with is configured for UK so the keyboard layout it expects is this
This sketch
#include "Keyboard.h"
byte keylist[] = { '`', '2', '3', '\'', '#', '\\' };
void setup() {
Keyboard.begin();
delay(1000);
// unshifted
for (byte i = 0; i < sizeof(keylist); i++) {
Keyboard.press(keylist[i]); delay(100);
Keyboard.release(keylist[i]); delay(100);
}
Keyboard.press(KEY_RETURN);
Keyboard.releaseAll();
// shifted
for (byte i = 0; i < sizeof(keylist); i++) {
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press(keylist[i]);
delay(100);
Keyboard.releaseAll();
delay(100);
}
}
void loop() {
delay(1000);
}
Creates this output (in a Notepad window)
`23'£#
¬"£@£~
I did try switching focus to a keyboard diagnostic tool - KeyHitter by Elite Keyboards which showed different results
` (0xDF, BIOS 0x29) down
` (0xDF, BIOS 0x29) up
2 (0x32, BIOS 0x03) down
2 (0x32, BIOS 0x03) up
3 (0x33, BIOS 0x04) down
3 (0x33, BIOS 0x04) up
' (0xC0, BIOS 0x28) down
' (0xC0, BIOS 0x28) up
LShift (0x10, BIOS 0x2a) down
3 (0x33, BIOS 0x04) down
LShift (0x10, BIOS 0x2a) up
3 (0x33, BIOS 0x04) up
\ (0xDE, BIOS 0x2B) down
\ (0xDE, BIOS 0x2B) up
So the Arduino Keyboard library unhelpfully translates '#' into shift+3 but I'm mystified why Keyhitter sees that '\\' produces the expected \ but other programs see it producing #! I guess Keyhitter intercepts keystrokes at a lower level than normal applications - for example it shows Win being pressed without Windows opening a start-menu.
The result in Notepad is typical of the effect produced in normal applications. So that's probably more relevant.
I can work around the '#' producing a shift+3 since '\\' produces # but how then do I generate a \?
