G'day guys.
First things first, as you might see I am completely new to the Arduino community so have mercy with me. 
Currently I am trying to rewrite the Keyboard.cpp (located in C:\Program Files (x86)\Arduino\libraries\Keyboard\src) to get the Arduino typing on the German keyboard layout instead of the standard US layout because I'm trying to make a BadUSB kinda thing.
So far so good, I've managed it to get Ardunio to type the most of the ASCII symbols correct on the German keyboard layout, but I keep failing at certain symbols.. and that's where I need your help because I don't know how get it up and running.
The characters I am failing with are:
what the Arduino types | dec - what he is supposed to type | dec
q 64 - @ 64
8 91 - [ 91
ß 92 - \ 92
9 93 - ] 93
7 123 - { 123
< 124 - | 124
0 125 - } 125
+ 126 - ~ 126
Correct me if I am wrong because I know that not every character is known to the ASCII table like the ß, but these should be possible to type.
My current Keyboard.cpp file is attached to the topic.
I hope you guys can help me out!
Have a nice day and Happy Easter. 
Keyboard.cpp (9.28 KB)
You have to monitor the state of the AltGr key and, if pressed, modify the key code as required. Processing is very similar to the CTRL and SHIFT key modifiers.
Thanks for your quick response!
But should'nt this already declared with the lines:
void initAltGr() {
_altFine = true;
_altGrMap[126] = true; // ~
_altGrMap[123] = true; // {
_altGrMap[91] = true; // [
_altGrMap[93] = true; // ]
_altGrMap[125] = true; // }
_altGrMap[92] = true; // bslash
_altGrMap[124] = true; // |
_altGrMap[64] = true; // @
or am I getting this wrong? (I mean obviously I am getting it wrong otherwise it would work
) Also tried to declare the AltGr Key modifier similar to the SHIFT key modifier but the Ardunio still spits out the "wrong" characters.
I'd show the SHIFT, CTRL, ALT and AltGr state on LEDs. Then you can see whether AltGr is detected properly.
Alright, that's actually a good idea. Could you give me some advice how to realise or some resources?
Because as already mentioned, I'm a total newbie regarding the Arduino.
The ASCII table only has eight bits. Seven of those eight are used for the keycode. The 8th bit is used as a flag to indicate that the Left Shift modifier should be activated with that keycode to get the right ASCII character on the US keyboard. It is not clear what the "altGrMap" actually does but it seems to be just to add a 9th bit to the ASCII table. Is "initAltGr()" called from anywhere? Is the table used anywhere? I don't see it used in Keyboard::press() where one would expect it to be.
I quickly looked into the .cpp too and it seems like you are totaly right. The "initAltGr()" isn't recalled elsewhere.
It seems like the function has no point at all.
So any further advice how to implement this function properly or any other option how to fix my problem at all?
Because unfortunately I am not really into the Arduino/C/C++ language..
Find out how and where the CTRL and SHIFT modifier keys are handled. Then add equivalent handling for AltGr.
Sarryaz:
So any further advice how to implement this function properly or any other option how to fix my problem at all?
Because unfortunately I am not really into the Arduino/C/C++ language..
The keycodes sent by the Arduino only represent which key on the keyboard is being pressed. Since most keys on the US-English keyboard have two ASCII characters associated with them, the table to map ASCII characters to keycodes has to also encode if the ASCII character is the unshifted or shifted graphic on the key. For many languages, one shift key is not enough to type all of the common characters so many keys get a THIRD character and a second shift key: the AltGraphic shift.
In the .press() and .release() functions you would add code similar to the shift code:
if (k & 0x80) { // it's a capital letter or other character reached with shift
_keyReport.modifiers |= 0x02; // the left shift modifier
k &= 0x7F;
}
but for the AltGr key (known in USB as the left Alt modifier key)
// Put AFTER the shift code so 'k' is already masked with 0x7F
if (_altGrMap[k]) { // The Alt Graphic character on a key
_keyReport.modifiers |= 0x04; // the left alt modifier
}
Be sure to call initAltGr() from Keyboard::begin() to initialize the table. To save SRAM you can put the _altGrMap array in PROGMEM but then you would have to initialize it at compile time and use pgm_read_byte() to read from it.