I am creating a keyboard and the PC I use it with is configured for UK so the keyboard layout it expects is this
I've highlighted the ISO-UK vs ANSI-US differences but the only key I am having real problems with is the backslash key.
My physical layout is actually this (ortholinear "Planck") but it's essentially the same except with two logical layers and variation in positioning.
The above is a fully functional UK-layout keyboard with the exception of the "\" key.
The sketch I am using is too large and distracting to post here but the following test 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
12:31.0675 ` (0xDF, BIOS 0x29) DOWN
12:31.0771 ` (0xDF, BIOS 0x29) UP -> 100ms
12:32.0772 2 (0x32, BIOS 0x03) DOWN
12:32.0871 2 (0x32, BIOS 0x03) UP -> 100ms
12:33.0872 3 (0x33, BIOS 0x04) DOWN
12:33.0972 3 (0x33, BIOS 0x04) UP -> 100ms
12:34.0972 ' (0xC0, BIOS 0x28) DOWN
12:35.0072 ' (0xC0, BIOS 0x28) UP -> 100ms
12:36.0072 LShift (0x10, BIOS 0x2A) DOWN
12:36.0082 3 (0x33, BIOS 0x04) DOWN
12:36.0172 LShift (0x10, BIOS 0x2A) UP -> 100ms
12:36.0182 3 (0x33, BIOS 0x04) UP -> 100ms
12:37.0172 \ (0xDE, BIOS 0x2B) DOWN
12:37.0272 \ (0xDE, BIOS 0x2B) UP -> 100ms
12:38.0271 Enter (0x0D, BIOS 0x1C) DOWN
12:38.0273 Enter (0x0D, BIOS 0x1C) UP -> 2ms
...
So the Arduino Keyboard
library translates '#'
into shift
+3
which is unhelpful for UK users 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 correctly shows Win
being pressed but prevents 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 \
?
for (byte i = 0; i <= 255; i++) { Keyboard.press(i) .......
.... one of the values should generate the desired character ... then use that value instead of'\\'
Win
followed by sayF1
- so I tried an app that I suspect captures keystrokes at a low level - but that wasn't too helpful. I may try your suggestion if I can work in some safeguards so that I have time to work out what's happening before the system descends into a frenzied chaos.if ( i != Win ) Keyboard.press(i);
Keyboard.press(0xEC)
produces "\" in Notepad and when used in conjunction with shift produces the expected "|".