Skip to main content
3 of 8
added 13 characters in body

Using Keyboard library for ISO-UK layout

I am creating a keyboard and the PC I use it with is configured for UK so the keyboard layout it expects is this

UK keyboard with UK - Us differences highlighted

This sketch

#include "Keyboard.h"

byte keylist[] = { '`', '2', '3', '\'', '#', '\\' }; 

void setup() {
  Keyboard.begin();
  delay(1000);
  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();
  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 Keyboard library unhelpfully translates '#' into shift+3 but I'm mystified why Keyhitter sees that '\\' produces the expected \ but other programs see it producing #!

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 \?