Skip to content

Commit

Permalink
otg keymap
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevaev committed Sep 26, 2019
1 parent cbebefc commit 31c17bb
Show file tree
Hide file tree
Showing 6 changed files with 470 additions and 194 deletions.
16 changes: 10 additions & 6 deletions genmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
# =====
@dataclasses.dataclass(frozen=True)
class _KeyMapping:
serial_hid_code: int
serial_hid_key: str
web_key: str
serial_code: int
arduino_key: str
otg_code: int
otg_is_modifier: bool


def _read_keymap_in(path: str) -> List[_KeyMapping]:
Expand All @@ -45,11 +47,13 @@ def _read_keymap_in(path: str) -> List[_KeyMapping]:
line = line.strip()
if len(line) > 0 and not line.startswith("#"):
parts = list(map(str.strip, line.split()))
if len(parts) >= 3:
if len(parts) >= 5:
keymap.append(_KeyMapping(
serial_hid_code=int(parts[0]),
serial_hid_key=parts[1],
web_key=parts[2],
web_key=parts[0],
serial_code=int(parts[1]),
arduino_key=parts[2],
otg_code=int(parts[3], 16),
otg_is_modifier=(parts[4].lower() == "m"),
))
return keymap

Expand Down
4 changes: 2 additions & 2 deletions hid/src/keymap.h.mako
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
<%! import operator %>
INLINE KeyboardKeycode keymap(uint8_t code) {
switch(code) {
% for km in sorted(keymap, key=operator.attrgetter("serial_hid_key")):
case ${km.serial_hid_code}: return ${km.serial_hid_key};
% for km in sorted(keymap, key=operator.attrgetter("arduino_key")):
case ${km.serial_code}: return ${km.arduino_key};
% endfor
default: return KEY_ERROR_UNDEFINED;
}
Expand Down
181 changes: 91 additions & 90 deletions keymap.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,98 +20,99 @@
# ========================================================================== #


# https://github.com/NicoHood/HID/blob/master/src/HID-APIs/ImprovedKeylayouts.h
# https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code
# https://github.com/NicoHood/HID/blob/master/src/HID-APIs/ImprovedKeylayouts.h
# https://gist.github.com/MightyPork/6da26e382a7ad91b5496ee55fdc73db2

# ----------------------------------
# KVMD | Arduino HID | JS
# ----------------------------------
1 KEY_A KeyA
2 KEY_B KeyB
3 KEY_C KeyC
4 KEY_D KeyD
5 KEY_E KeyE
6 KEY_F KeyF
7 KEY_G KeyG
8 KEY_H KeyH
9 KEY_I KeyI
10 KEY_J KeyJ
11 KEY_K KeyK
12 KEY_L KeyL
13 KEY_M KeyM
14 KEY_N KeyN
15 KEY_O KeyO
16 KEY_P KeyP
17 KEY_Q KeyQ
18 KEY_R KeyR
19 KEY_S KeyS
20 KEY_T KeyT
21 KEY_U KeyU
22 KEY_V KeyV
23 KEY_W KeyW
24 KEY_X KeyX
25 KEY_Y KeyY
26 KEY_Z KeyZ
27 KEY_1 Digit1
28 KEY_2 Digit2
29 KEY_3 Digit3
30 KEY_4 Digit4
31 KEY_5 Digit5
32 KEY_6 Digit6
33 KEY_7 Digit7
34 KEY_8 Digit8
35 KEY_9 Digit9
36 KEY_0 Digit0
37 KEY_ENTER Enter
38 KEY_ESC Escape
39 KEY_BACKSPACE Backspace
40 KEY_TAB Tab
41 KEY_SPACE Space
42 KEY_MINUS Minus
43 KEY_EQUAL Equal
44 KEY_LEFT_BRACE BracketLeft
45 KEY_RIGHT_BRACE BracketRight
46 KEY_BACKSLASH Backslash
47 KEY_SEMICOLON Semicolon
48 KEY_QUOTE Quote
49 KEY_TILDE Backquote
50 KEY_COMMA Comma
51 KEY_PERIOD Period
52 KEY_SLASH Slash
53 KEY_CAPS_LOCK CapsLock
54 KEY_F1 F1
55 KEY_F2 F2
56 KEY_F3 F3
57 KEY_F4 F4
58 KEY_F5 F5
59 KEY_F6 F6
60 KEY_F7 F7
61 KEY_F8 F8
62 KEY_F9 F9
63 KEY_F10 F10
64 KEY_F11 F11
65 KEY_F12 F12
66 KEY_PRINT PrintScreen
67 KEY_INSERT Insert
68 KEY_HOME Home
69 KEY_PAGE_UP PageUp
70 KEY_DELETE Delete
71 KEY_END End
72 KEY_PAGE_DOWN PageDown
73 KEY_RIGHT_ARROW ArrowRight
74 KEY_LEFT_ARROW ArrowLeft
75 KEY_DOWN_ARROW ArrowDown
76 KEY_UP_ARROW ArrowUp
77 KEY_LEFT_CTRL ControlLeft
78 KEY_LEFT_SHIFT ShiftLeft
79 KEY_LEFT_ALT AltLeft
80 KEY_LEFT_GUI MetaLeft
81 KEY_RIGHT_CTRL ControlRight
82 KEY_RIGHT_SHIFT ShiftRight
83 KEY_RIGHT_ALT AltRight
84 KEY_RIGHT_GUI MetaRight
85 KEY_PAUSE Pause
86 KEY_SCROLL_LOCK ScrollLock
# -----------------------------------------------------------------------------------
# Web | Serial code | Arduino key | OTG code + modifier flag
# -----------------------------------------------------------------------------------
KeyA 1 KEY_A 0x04 -
KeyB 2 KEY_B 0x05 -
KeyC 3 KEY_C 0x06 -
KeyD 4 KEY_D 0x07 -
KeyE 5 KEY_E 0x08 -
KeyF 6 KEY_F 0x09 -
KeyG 7 KEY_G 0x0a -
KeyH 8 KEY_H 0x0b -
KeyI 9 KEY_I 0x0c -
KeyJ 10 KEY_J 0x0d -
KeyK 11 KEY_K 0x0e -
KeyL 12 KEY_L 0x0f -
KeyM 13 KEY_M 0x10 -
KeyN 14 KEY_N 0x11 -
KeyO 15 KEY_O 0x12 -
KeyP 16 KEY_P 0x13 -
KeyQ 17 KEY_Q 0x14 -
KeyR 18 KEY_R 0x15 -
KeyS 19 KEY_S 0x16 -
KeyT 20 KEY_T 0x17 -
KeyU 21 KEY_U 0x18 -
KeyV 22 KEY_V 0x19 -
KeyW 23 KEY_W 0x1a -
KeyX 24 KEY_X 0x1b -
KeyY 25 KEY_Y 0x1c -
KeyZ 26 KEY_Z 0x1d -
Digit1 27 KEY_1 0x1e -
Digit2 28 KEY_2 0x1f -
Digit3 29 KEY_3 0x20 -
Digit4 30 KEY_4 0x21 -
Digit5 31 KEY_5 0x22 -
Digit6 32 KEY_6 0x23 -
Digit7 33 KEY_7 0x24 -
Digit8 34 KEY_8 0x25 -
Digit9 35 KEY_9 0x26 -
Digit0 36 KEY_0 0x27 -
Enter 37 KEY_ENTER 0x28 -
Escape 38 KEY_ESC 0x29 -
Backspace 39 KEY_BACKSPACE 0x2a -
Tab 40 KEY_TAB 0x2b -
Space 41 KEY_SPACE 0x2c -
Minus 42 KEY_MINUS 0x2d -
Equal 43 KEY_EQUAL 0x2e -
BracketLeft 44 KEY_LEFT_BRACE 0x2f -
BracketRight 45 KEY_RIGHT_BRACE 0x30 -
Backslash 46 KEY_BACKSLASH 0x31 -
Semicolon 47 KEY_SEMICOLON 0x33 -
Quote 48 KEY_QUOTE 0x34 -
Backquote 49 KEY_TILDE 0x35 -
Comma 50 KEY_COMMA 0x36 -
Period 51 KEY_PERIOD 0x37 -
Slash 52 KEY_SLASH 0x38 -
CapsLock 53 KEY_CAPS_LOCK 0x39 -
F1 54 KEY_F1 0x3a -
F2 55 KEY_F2 0x3b -
F3 56 KEY_F3 0x3c -
F4 57 KEY_F4 0x3d -
F5 58 KEY_F5 0x3e -
F6 59 KEY_F6 0x3f -
F7 60 KEY_F7 0x40 -
F8 61 KEY_F8 0x41 -
F9 62 KEY_F9 0x42 -
F10 63 KEY_F10 0x43 -
F11 64 KEY_F11 0x44 -
F12 65 KEY_F12 0x45 -
PrintScreen 66 KEY_PRINT 0x46 -
Insert 67 KEY_INSERT 0x49 -
Home 68 KEY_HOME 0x4a -
PageUp 69 KEY_PAGE_UP 0x4b -
Delete 70 KEY_DELETE 0x4c -
End 71 KEY_END 0x4d -
PageDown 72 KEY_PAGE_DOWN 0x4e -
ArrowRight 73 KEY_RIGHT_ARROW 0x4f -
ArrowLeft 74 KEY_LEFT_ARROW 0x50 -
ArrowDown 75 KEY_DOWN_ARROW 0x51 -
ArrowUp 76 KEY_UP_ARROW 0x52 -
ControlLeft 77 KEY_LEFT_CTRL 0x01 m
ShiftLeft 78 KEY_LEFT_SHIFT 0x02 m
AltLeft 79 KEY_LEFT_ALT 0x04 m
MetaLeft 80 KEY_LEFT_GUI 0x08 m
ControlRight 81 KEY_RIGHT_CTRL 0x10 m
ShiftRight 82 KEY_RIGHT_SHIFT 0x20 m
AltRight 83 KEY_RIGHT_ALT 0x40 m
MetaRight 84 KEY_RIGHT_GUI 0x80 m
Pause 85 KEY_PAUSE 0x48 -
ScrollLock 86 KEY_SCROLL_LOCK 0x47 -
# KEY_NON_US_NUM
# KEY_NUM_LOCK
# KEYPAD_DIVIDE
Expand Down
Loading

0 comments on commit 31c17bb

Please sign in to comment.