Skip to content

Commit

Permalink
Update locales to support accents and other missing keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Spacehuhn committed Jan 25, 2022
1 parent 106c686 commit ff4a3fa
Show file tree
Hide file tree
Showing 17 changed files with 2,497 additions and 2,113 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@ For example:
`locale_xx.h` -> `locale_de.h`,
`ascii_xx` -> `ascii_de`,
`locale_xx` -> `locale_de`,
`extended_ascii_xx` -> `extended_ascii_de`,
`utf8_xx` -> `utf8_de`.
`combinations_xx` -> `combinations_de`,
4. Modify the ASCII array.
The ASCII array has a fixed size. Each row describes a key.
First a modifier key like `KEY_MOD_LSHIFT`, then a character key.
Expand All @@ -480,11 +480,11 @@ This is because German keyboards use QWERTZ instead of the QWERTY layout
and since the letter is uppercase, shift must be pressed as well.
Thankfully you don't have to trial and error everything, the Hak5 Community
translated a lot of layouts already [here](https://github.com/hak5darren/USB-Rubber-Ducky/tree/master/Encoder/resources). It's just written in a different syntax. For example, `ASCII_20` (20 in hexadecimal) is the 32th character in our ascii array.
5. Modify or create the extended ASCII array.
5. [deprecated] ~~Modify or create the extended ASCII array.
The extended ASCII array doesn't have a fixed size and is only as long as you make it.
First the character code. For example, [ä](https://theasciicode.com.ar/extended-ascii-code/letter-a-umlaut-diaeresis-a-umlaut-lowercase-ascii-code-132.html) has the index 132, or 84 in hex.
It doesn't use a modifier and sits where the apostrophe key is on a US keyboard:
`0x84, KEY_NONE, KEY_APOSTROPHE, // ä`.
`0x84, KEY_NONE, KEY_APOSTROPHE, // ä`.~~
6. Modify or create the UTF-8 array.
The UTF-8 array is variable in length, too.
The first 4 bytes are the character code.
Expand Down
55 changes: 40 additions & 15 deletions atmega_duck/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,46 @@ namespace keyboard {
uint8_t press(const char* strPtr) {
// Convert string pointer into a byte pointer
uint8_t* b = (uint8_t*)strPtr;


// Key combinations (accent keys)
// We have to check them first, because sometimes ASCII keys are in here
for (uint8_t i = 0; i<locale->combinations_len; ++i) {
uint8_t res = 0;

// Read utf8 code and match it with the given data
for (uint8_t j = 0; j<4; ++j) {
uint8_t key_code = pgm_read_byte(locale->combinations + (i * 8) + j);

if (key_code == 0) {
break;
}

if (key_code == b[j]) {
++res;
} else {
res = 0;
break;
}
}

// If a match was found, read out the data and type it
if (res > 0) {
uint8_t comboModifiers = pgm_read_byte(locale->combinations + (i * 8) + 4);
uint8_t comboKey = pgm_read_byte(locale->combinations + (i * 8) + 5);

uint8_t modifiers = pgm_read_byte(locale->combinations + (i * 8) + 6);
uint8_t key = pgm_read_byte(locale->combinations + (i * 8) + 7);

pressKey(comboKey, comboModifiers);
release();
pressKey(key, modifiers);
release();

// Return the number of extra bytes we used from the string pointer
return res-1;
}
}

// ASCII
if (b[0] < locale->ascii_len) {
uint8_t modifiers = pgm_read_byte(locale->ascii + (b[0] * 2) + 0);
Expand Down Expand Up @@ -155,20 +194,6 @@ namespace keyboard {
}
}

// Extended ASCII
for (uint8_t i = 0; i<locale->extended_ascii_len; ++i) {
uint8_t key_code = pgm_read_byte(locale->extended_ascii + (i * 3));

if (b[0] == key_code) {
uint8_t modifiers = pgm_read_byte(locale->extended_ascii + (i * 3) + 1);
uint8_t key = pgm_read_byte(locale->extended_ascii + (i * 3) + 2);

pressKey(key, modifiers);

return 0;
}
}

return 0;
}

Expand Down
Loading

0 comments on commit ff4a3fa

Please sign in to comment.