Problem with BE Keyboard layout

Hi everybody, I am having trouble with the code for my HID device. The code is the following :

#define SHIFT 0x80
const uint8_t _asciimap[128] =
{
0x00, // NUL
0x00, // SOH
0x00, // STX
0x00, // ETX
0x00, // EOT
0x00, // ENQ
0x00, // ACK
0x00, // BEL
0x2a, // BS Backspace
0x2b, // TAB Tab
0x28, // LF Enter
0x00, // VT
0x00, // FF
0x00, // CR
0x00, // SO
0x00, // SI
0x00, // DEL
0x00, // DC1
0x00, // DC2
0x00, // DC3
0x00, // DC4
0x00, // NAK
0x00, // SYN
0x00, // ETB
0x00, // CAN
0x00, // EM
0x00, // SUB
0x00, // ESC
0x00, // FS
0x00, // GS
0x00, // RS
0x00, // US

0x2c, // ' '
0x25, // !
0x20, // "
0x20, // #
0x30, // $
0x34|SHIFT, // %
0x1e, // &
0x21, // '
0x22, // (
0x2d, // )
0x31, // *
0x38|SHIFT, // +
0x10, // ,
0x2e, // -
0x36|SHIFT, // .
0x37|SHIFT, // /
0x27|SHIFT, // 0
0x1e|SHIFT, // 1
0x1f|SHIFT, // 2
0x20|SHIFT, // 3
0x21|SHIFT, // 4
0x22|SHIFT, // 5
0x23|SHIFT, // 6
0x24|SHIFT, // 7
0x25|SHIFT, // 8
0x26|SHIFT, // 9
0x37, // :
0x36, // ;
0x64, // <
0x38, // =
0x64|SHIFT, // >
0x10|SHIFT, // ?
0x27, // @
0x14|SHIFT, // A
0x05|SHIFT, // B
0x06|SHIFT, // C
0x07|SHIFT, // D
0x08|SHIFT, // E
0x09|SHIFT, // F
0x0a|SHIFT, // G
0x0b|SHIFT, // H
0x0c|SHIFT, // I
0x0d|SHIFT, // J
0x0e|SHIFT, // K
0x0f|SHIFT, // L
0x33|SHIFT, // M
0x11|SHIFT, // N
0x12|SHIFT, // O
0x13|SHIFT, // P
0x04|SHIFT, // Q
0x15|SHIFT, // R
0x16|SHIFT, // S
0x17|SHIFT, // T
0x18|SHIFT, // U
0x19|SHIFT, // V
0x1d|SHIFT, // W
0x1b|SHIFT, // X
0x1c|SHIFT, // Y
0x1a|SHIFT, // Z
0x22, // [
0x25, // bslash
0x2d, // ]
0x26, // ^
0x2e|SHIFT, // _
0x24, // `
0x14, // a
0x05, // b
0x06, // c
0x07, // d
0x08, // e
0x09, // f
0x0a, // g
0x0b, // h
0x0c, // i
0x0d, // j
0x0e, // k
0x0f, // l
0x33, // m
0x11, // n
0x12, // o
0x13, // p
0x04, // q
0x15, // r
0x16, // s
0x17, // t
0x18, // u
0x19, // v
0x1d, // w
0x1b, // x
0x1c, // y
0x1a, // z
0x21, // {
0x23, // |
0x2e, // }
0x1f, // ~
0 // DEL
};

// Init var
bool _altGrMap[128];
bool _altFine = false;

// Individually define all needed char
void initAltGr() {
_altFine = true;

_altGrMap[35] = true; // #
_altGrMap[64] = true; // @
_altGrMap[91] = true; // [
_altGrMap[92] = true; // bslash
_altGrMap[93] = true; // ]
_altGrMap[94] = true; // ^

_altGrMap[96] = true; // `

_altGrMap[123] = true; // {
_altGrMap[124] = true; // |
_altGrMap[125] = true; // }
_altGrMap[126] = true; // ~
}

When I try to execute something with my HID, multiple characters come out off, I found these misplacements on my BE keyboard:

!"#$%&'()+,-./0123456789:;<=>?[]^_{|}~ @
!""$%&'()
+,-./0123456789:;@=#?(@$(_'&à126 à

As you can see, some characters are just misplaced and others are completely missing ( <> for example )

I can't find a proper explanation on internet on how ascii works and the placements of my characters on my keyboard. So I'm here trying to find help.

If someone can help a complete noob, it would be greatly appreciated !!

Welcome to the forum. Please read the top post on how to properly post your code using tags and post your complete sketch. It will help people help you. Without your sketch, who knows what the problem is?

I think the 'asciimap' don't match your actual keyboard layout.

When you try to send an lower case 'a', the keyboard library uses the ASCII-code, which has 97, as index to 'ascimap' and find the scancode for the key that has to be pressed (and released) to get an 'a'.

A capital 'A' has ASCII-code 65, and in posisition 65 in asciimap the you will find the same scancode, but or'ed with SHIFT because that has to be pressed as well.

The keyboard itself is not concerned about ASCII-codes, only scancodes.
A particular key will return the same scancode regardless of (logical) keyboard-layout.

So, in short, you have to remap the 'asciimap' to match your keyboard.

Ok but how can I find a ascii map with I can base my code on that matches my keyboard layout ? I found something with unicode but doesn't help me really much so I am perplex, here's the link http://ascii-table.com/keyboard.php/120.
I am using a BE keyboard layout btw if someone can help!

Search the forum. There are several threads discussing this topic, for example this.

In Keyboard.cpp (normally located in C:\Program Files (x86)\Arduino\libraries\Keyboard\src) you will find the mapping of a basic US-keyboard. With this as a reference you can find the relationship between keys and HID-codes.

Example:
The 'a'-key in the US asciimap has HID-code 0x04. The BE-keyboard has the letter 'q' in this position.
Therefore the BE asciimap has 0x04 in the position for 'q'.

Oh ok I understand a little better, but in my case for a BE keyboard layout, "<" and ">" are on a key between the shift and the w, if I translate that on a US keyboard, it's on a key between the shift (leftend side) and the z key, witch don't exist on a US layout. So what can I do about that ?

I put in attachments where the key should be on a US layout so you can have a general idea, and the other attachment specifies the key it should replace, in that they say it's says that that specific key is for non-US keyboards. So, what should I do now ? Try and modify something in the HID file or something of that sort ?

Capture d’écran 2018-12-22 à 22.49.42.jpg

Capture d’écran 2018-12-22 à 22.49.59.jpg

Here is the document that shows which code goes with which key:

The section of interest starts on page 53.