Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RF Raw and RawBin codes and en-UK Keyboard on BadUSB #95

Merged
merged 4 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions lib/Bad_Usb_Lib/KeyboardLayout_en_UK.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* Standard US keyboard layout.
*/

#include "Keyboard_en_UK.h"

extern const uint8_t KeyboardLayout_en_UK[128] PROGMEM =
{
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, // ' '
0x1e|SHIFT, // !
0x1f|SHIFT, // " ok
0x31, // # ok
0x21|SHIFT, // $
0x22|SHIFT, // %
0x24|SHIFT, // &
0x34, // ' ok
0x26|SHIFT, // (
0x27|SHIFT, // )
0x25|SHIFT, // *
0x2e|SHIFT, // +
0x36, // ,
0x2d, // -
0x37, // .
0x38, // /
0x27, // 0
0x1e, // 1
0x1f, // 2
0x20, // 3
0x21, // 4
0x22, // 5
0x23, // 6
0x24, // 7
0x25, // 8
0x26, // 9
0x33|SHIFT, // :
0x33, // ;
0x36|SHIFT, // <
0x2e, // =
0x37|SHIFT, // >
0x38|SHIFT, // ?
0x34|SHIFT, // @ ok
0x04|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
0x10|SHIFT, // M
0x11|SHIFT, // N
0x12|SHIFT, // O
0x13|SHIFT, // P
0x14|SHIFT, // Q
0x15|SHIFT, // R
0x16|SHIFT, // S
0x17|SHIFT, // T
0x18|SHIFT, // U
0x19|SHIFT, // V
0x1a|SHIFT, // W
0x1b|SHIFT, // X
0x1c|SHIFT, // Y
0x1d|SHIFT, // Z
0x2f, // [
0x64, // bslash ok
0x30, // ]
0x23|SHIFT, // ^
0x2d|SHIFT, // _
0x35, // `
0x04, // a
0x05, // b
0x06, // c
0x07, // d
0x08, // e
0x09, // f
0x0a, // g
0x0b, // h
0x0c, // i
0x0d, // j
0x0e, // k
0x0f, // l
0x10, // m
0x11, // n
0x12, // o
0x13, // p
0x14, // q
0x15, // r
0x16, // s
0x17, // t
0x18, // u
0x19, // v
0x1a, // w
0x1b, // x
0x1c, // y
0x1d, // z
0x2f|SHIFT, // {
0x35, // | ok
0x30|SHIFT, // }
0x31|SHIFT, // ~ ok
0x00 // DEL
};
67 changes: 67 additions & 0 deletions lib/Bad_Usb_Lib/Keyboard_en_UK.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
KeyboardLayout.h

This file is not part of the public API. It is meant to be included
only in Keyboard.cpp and the keyboard layout files. Layout files map
ASCII character codes to keyboard scan codes (technically, to USB HID
Usage codes), possibly altered by the SHIFT or ALT_GR modifiers.
Non-ACSII characters (anything outside the 7-bit range NUL..DEL) are
not supported.

== Creating your own layout ==

In order to create your own layout file, copy an existing layout that
is similar to yours, then modify it to use the correct keys. The
layout is an array in ASCII order. Each entry contains a scan code,
possibly modified by "|SHIFT" or "|ALT_GR", as in this excerpt from
the Italian layout:

0x35, // bslash
0x30|ALT_GR, // ]
0x2e|SHIFT, // ^

Do not change the control characters (those before scan code 0x2c,
corresponding to space). Do not attempt to grow the table past DEL. Do
not use both SHIFT and ALT_GR on the same character: this is not
supported. Unsupported characters should have 0x00 as scan code.

For a keyboard with an ISO physical layout, use the scan codes below:

+---+---+---+---+---+---+---+---+---+---+---+---+---+-------+
|35 |1e |1f |20 |21 |22 |23 |24 |25 |26 |27 |2d |2e |BackSp |
+---+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-----+
| Tab |14 |1a |08 |15 |17 |1c |18 |0c |12 |13 |2f |30 | Ret |
+-----++--++--++--++--++--++--++--++--++--++--++--++--++ |
|CapsL |04 |16 |07 |09 |0a |0b |0d |0e |0f |33 |34 |31 | |
+----+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+---+----+
|Shi.|32 |1d |1b |06 |19 |05 |11 |10 |36 |37 |38 | Shift |
+----+---++--+-+-+---+---+---+---+---+--++---+---++----+----+
|Ctrl|Win |Alt | |AlGr|Win |Menu|Ctrl|
+----+----+----+------------------------+----+----+----+----+

The ANSI layout is identical except that key 0x31 is above (rather
than next to) Return, and there is not key 0x32.

Give a unique name to the layout array, then declare it in Keyboard.h
with a line of the form:

extern const uint8_t KeyboardLayout_xx_YY[];

== Encoding details ==

All scan codes are less than 0x80, which makes bit 7 available to
signal that a modifier (Shift or AltGr) is needed to generate the
character. With only one exception, keys that are used with modifiers
have scan codes that are less than 0x40. This makes bit 6 available
to signal whether the modifier is Shift or AltGr. The exception is
0x64, the key next next to Left Shift on the ISO layout (and absent
from the ANSI layout). We handle it by replacing its value by 0x32 in
the layout arrays.
*/

#include <Arduino.h>

#define SHIFT 0x80
#define ALT_GR 0xc0
#define ISO_KEY 0x64
#define ISO_REPLACEMENT 0x32
1 change: 1 addition & 0 deletions lib/Bad_Usb_Lib/USBHIDKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ typedef union {
// Supported keyboard layouts
extern const uint8_t KeyboardLayout_de_DE[];
extern const uint8_t KeyboardLayout_en_US[];
extern const uint8_t KeyboardLayout_en_UK[];
extern const uint8_t KeyboardLayout_es_ES[];
extern const uint8_t KeyboardLayout_fr_FR[];
extern const uint8_t KeyboardLayout_it_IT[];
Expand Down
22 changes: 11 additions & 11 deletions src/modules/others/bad_usb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,17 @@ void usb_setup() {
drawMainMenu(4);

options = {
{"US Inter", [=]() { chooseKb(KeyboardLayout_en_US); }},
{"PT-BR ABNT2", [=]() { chooseKb(KeyboardLayout_pt_BR); }},
{"PT-PT", [=]() { chooseKb(KeyboardLayout_pt_PT); }},
{"AZERTY FR", [=]() { chooseKb(KeyboardLayout_fr_FR); }},
{"es-Espñol", [=]() { chooseKb(KeyboardLayout_es_ES); }},
{"it-Italiano", [=]() { chooseKb(KeyboardLayout_it_IT); }},
{"de-DE", [=]() { chooseKb(KeyboardLayout_de_DE); }},
{"sv-SE", [=]() { chooseKb(KeyboardLayout_sv_SE); }},
{"da-DK", [=]() { chooseKb(KeyboardLayout_da_DK); }},
{"hu-HU", [=]() { chooseKb(KeyboardLayout_hu_HU); }},

{"US Inter", [=]() { chooseKb(KeyboardLayout_en_US); }},
{"PT-BR ABNT2", [=]() { chooseKb(KeyboardLayout_pt_BR); }},
{"PT-Portugal", [=]() { chooseKb(KeyboardLayout_pt_PT); }},
{"AZERTY FR", [=]() { chooseKb(KeyboardLayout_fr_FR); }},
{"es-Espanol", [=]() { chooseKb(KeyboardLayout_es_ES); }},
{"it-Italiano", [=]() { chooseKb(KeyboardLayout_it_IT); }},
{"en-UK", [=]() { chooseKb(KeyboardLayout_en_UK); }},
{"de-DE", [=]() { chooseKb(KeyboardLayout_de_DE); }},
{"sv-SE", [=]() { chooseKb(KeyboardLayout_sv_SE); }},
{"da-DK", [=]() { chooseKb(KeyboardLayout_da_DK); }},
{"hu-HU", [=]() { chooseKb(KeyboardLayout_hu_HU); }},
};
delay(200);
loopOptions(options,false,true,"Keyboard Layout");
Expand Down
Loading
Loading