diff options
author | Devaev Maxim <[email protected]> | 2020-07-15 17:05:04 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-07-15 17:05:04 +0300 |
commit | 0d857282fe8df38f1cddffda78487cefbf21f3a2 (patch) | |
tree | b71336f5aaf92398a8b62a9a75434f09ef27ab86 | |
parent | 09c202d67c92ff44cbc76724903e7ddbae3a4b15 (diff) |
csv
-rw-r--r-- | Makefile | 4 | ||||
-rwxr-xr-x | genmap.py | 65 | ||||
-rw-r--r-- | keymap.csv | 105 | ||||
-rw-r--r-- | keymap.in | 136 |
4 files changed, 145 insertions, 165 deletions
@@ -138,8 +138,8 @@ keymap: testenv docker run --user `id -u`:`id -g` --rm \ --volume `pwd`:/src \ -it $(TESTENV_IMAGE) bash -c "cd src \ - && ./genmap.py keymap.in kvmd/keyboard/mappings.py.mako kvmd/keyboard/mappings.py \ - && ./genmap.py keymap.in hid/src/keymap.h.mako hid/src/keymap.h \ + && ./genmap.py keymap.csv kvmd/keyboard/mappings.py.mako kvmd/keyboard/mappings.py \ + && ./genmap.py keymap.csv hid/src/keymap.h.mako hid/src/keymap.h \ " @@ -22,6 +22,7 @@ import sys +import csv import textwrap import dataclasses @@ -66,32 +67,29 @@ def _resolve_keysym(name: str) -> int: return code -def _read_keymap_in(path: str) -> List[_KeyMapping]: +def _read_keymap_csv(path: str) -> List[_KeyMapping]: keymap: List[_KeyMapping] = [] with open(path) as keymap_file: - for line in keymap_file: - line = line.strip() - if len(line) > 0 and not line.startswith("#"): - parts = list(map(str.strip, line.split())) - if len(parts) >= 6: - otg_is_modifier = parts[3].startswith("^") - otg_code = int((parts[3][1:] if otg_is_modifier else parts[3]), 16) - - x11_keys: Set[_X11Key] = set() - for x11_name in parts[5].split(","): - x11_shift = x11_name.startswith("^") - x11_name = (x11_name[1:] if x11_shift else x11_name) - x11_code = _resolve_keysym(x11_name) - x11_keys.add(_X11Key(x11_name, x11_code, x11_shift)) - - keymap.append(_KeyMapping( - web_name=parts[0], - serial_code=int(parts[1]), - arduino_name=parts[2], - otg_key=_OtgKey(otg_code, otg_is_modifier), - at1_code=int(parts[4], 16), - x11_keys=x11_keys, - )) + for row in csv.DictReader(keymap_file): + if len(row) >= 6: + otg_is_modifier = row["otg_key"].startswith("^") + otg_code = int((row["otg_key"][1:] if otg_is_modifier else row["otg_key"]), 16) + + x11_keys: Set[_X11Key] = set() + for x11_name in row["x11_names"].split(","): + x11_shift = x11_name.startswith("^") + x11_name = (x11_name[1:] if x11_shift else x11_name) + x11_code = _resolve_keysym(x11_name) + x11_keys.add(_X11Key(x11_name, x11_code, x11_shift)) + + keymap.append(_KeyMapping( + web_name=row["web_name"], + serial_code=int(row["serial_code"]), + arduino_name=row["arduino_name"], + otg_key=_OtgKey(otg_code, otg_is_modifier), + at1_code=int(row["at1_code"], 16), + x11_keys=x11_keys, + )) return keymap @@ -105,9 +103,22 @@ def _render_keymap(keymap: List[_KeyMapping], template_path: str, out_path: str) # ===== def main() -> None: - assert len(sys.argv) == 4, f"{sys.argv[0]} <keymap.in> <template> <out>" - - keymap = _read_keymap_in(sys.argv[1]) + # https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code/code_values + # https://github.com/NicoHood/HID/blob/master/src/KeyboardLayouts/ImprovedKeylayouts.h + # https://gist.github.com/MightyPork/6da26e382a7ad91b5496ee55fdc73db2 + # https://github.com/qemu/keycodemapdb/blob/master/data/keymaps.csv + + # Fields list: + # - Web + # - Serial code + # - Arduino key + # - OTG code (^ for mod) + # - AT set1 + # -X11 keysyms (^ for shift) + + assert len(sys.argv) == 4, f"{sys.argv[0]} <keymap.csv> <template> <out>" + + keymap = _read_keymap_csv(sys.argv[1]) _render_keymap(keymap, sys.argv[2], sys.argv[3]) diff --git a/keymap.csv b/keymap.csv new file mode 100644 index 00000000..eea99353 --- /dev/null +++ b/keymap.csv @@ -0,0 +1,105 @@ +web_name,serial_code,arduino_name,otg_key,at1_code,x11_names +KeyA,1,KEY_A,0x04,0x1e,"^XK_A,XK_a" +KeyB,2,KEY_B,0x05,0x30,"^XK_B,XK_b" +KeyC,3,KEY_C,0x06,0x2e,"^XK_C,XK_c" +KeyD,4,KEY_D,0x07,0x20,"^XK_D,XK_d" +KeyE,5,KEY_E,0x08,0x12,"^XK_E,XK_e" +KeyF,6,KEY_F,0x09,0x21,"^XK_F,XK_f" +KeyG,7,KEY_G,0x0a,0x22,"^XK_G,XK_g" +KeyH,8,KEY_H,0x0b,0x23,"^XK_H,XK_h" +KeyI,9,KEY_I,0x0c,0x17,"^XK_I,XK_i" +KeyJ,10,KEY_J,0x0d,0x24,"^XK_J,XK_j" +KeyK,11,KEY_K,0x0e,0x25,"^XK_K,XK_k" +KeyL,12,KEY_L,0x0f,0x26,"^XK_L,XK_l" +KeyM,13,KEY_M,0x10,0x32,"^XK_M,XK_m" +KeyN,14,KEY_N,0x11,0x31,"^XK_N,XK_n" +KeyO,15,KEY_O,0x12,0x18,"^XK_O,XK_o" +KeyP,16,KEY_P,0x13,0x19,"^XK_P,XK_p" +KeyQ,17,KEY_Q,0x14,0x10,"^XK_Q,XK_q" +KeyR,18,KEY_R,0x15,0x13,"^XK_R,XK_r" +KeyS,19,KEY_S,0x16,0x1f,"^XK_S,XK_s" +KeyT,20,KEY_T,0x17,0x14,"^XK_T,XK_t" +KeyU,21,KEY_U,0x18,0x16,"^XK_U,XK_u" +KeyV,22,KEY_V,0x19,0x2f,"^XK_V,XK_v" +KeyW,23,KEY_W,0x1a,0x11,"^XK_W,XK_w" +KeyX,24,KEY_X,0x1b,0x2d,"^XK_X,XK_x" +KeyY,25,KEY_Y,0x1c,0x15,"^XK_Y,XK_y" +KeyZ,26,KEY_Z,0x1d,0x2c,"^XK_Z,XK_z" +Digit1,27,KEY_1,0x1e,0x02,"XK_1,^XK_exclam" +Digit2,28,KEY_2,0x1f,0x03,"XK_2,^XK_at" +Digit3,29,KEY_3,0x20,0x04,"XK_3,^XK_numbersign" +Digit4,30,KEY_4,0x21,0x05,"XK_4,^XK_dollar" +Digit5,31,KEY_5,0x22,0x06,"XK_5,^XK_percent" +Digit6,32,KEY_6,0x23,0x07,"XK_6,^XK_asciicircum" +Digit7,33,KEY_7,0x24,0x08,"XK_7,^XK_ampersand" +Digit8,34,KEY_8,0x25,0x09,"XK_8,^XK_asterisk" +Digit9,35,KEY_9,0x26,0x0a,"XK_9,^XK_parenleft" +Digit0,36,KEY_0,0x27,0x0b,"XK_0,^XK_parenright" +Enter,37,KEY_ENTER,0x28,0x1c,XK_Return +Escape,38,KEY_ESC,0x29,0x01,XK_Escape +Backspace,39,KEY_BACKSPACE,0x2a,0x0e,XK_BackSpace +Tab,40,KEY_TAB,0x2b,0x0f,XK_Tab +Space,41,KEY_SPACE,0x2c,0x39,XK_space +Minus,42,KEY_MINUS,0x2d,0x0c,"XK_minus,^XK_underscore" +Equal,43,KEY_EQUAL,0x2e,0x0d,"XK_equal,^XK_plus" +BracketLeft,44,KEY_LEFT_BRACE,0x2f,0x1a,"XK_bracketleft,^XK_braceleft" +BracketRight,45,KEY_RIGHT_BRACE,0x30,0x1b,"XK_bracketright,^XK_braceright" +Backslash,46,KEY_BACKSLASH,0x31,0x2b,"XK_backslash,^XK_bar" +Semicolon,47,KEY_SEMICOLON,0x33,0x27,"XK_semicolon,^XK_colon" +Quote,48,KEY_QUOTE,0x34,0x28,"XK_apostrophe,^XK_quotedbl" +Backquote,49,KEY_TILDE,0x35,0x29,"XK_grave,^XK_asciitilde" +Comma,50,KEY_COMMA,0x36,0x33,"XK_comma,^XK_less" +Period,51,KEY_PERIOD,0x37,0x34,"XK_period,^XK_greater" +Slash,52,KEY_SLASH,0x38,0x35,"XK_slash,^XK_question" +CapsLock,53,KEY_CAPS_LOCK,0x39,0x3a,XK_Caps_Lock +F1,54,KEY_F1,0x3a,0x3b,XK_F1 +F2,55,KEY_F2,0x3b,0x3c,XK_F2 +F3,56,KEY_F3,0x3c,0x3d,XK_F3 +F4,57,KEY_F4,0x3d,0x3e,XK_F4 +F5,58,KEY_F5,0x3e,0x3f,XK_F5 +F6,59,KEY_F6,0x3f,0x40,XK_F6 +F7,60,KEY_F7,0x40,0x41,XK_F7 +F8,61,KEY_F8,0x41,0x42,XK_F8 +F9,62,KEY_F9,0x42,0x43,XK_F9 +F10,63,KEY_F10,0x43,0x44,XK_F10 +F11,64,KEY_F11,0x44,0x57,XK_F11 +F12,65,KEY_F12,0x45,0x58,XK_F12 +PrintScreen,66,KEY_PRINT,0x46,0x54,XK_Sys_Req +Insert,67,KEY_INSERT,0x49,0xe052,XK_Insert +Home,68,KEY_HOME,0x4a,0xe047,XK_Home +PageUp,69,KEY_PAGE_UP,0x4b,0xe049,XK_Page_Up +Delete,70,KEY_DELETE,0x4c,0xe053,XK_Delete +End,71,KEY_END,0x4d,0xe04f,XK_End +PageDown,72,KEY_PAGE_DOWN,0x4e,0xe051,XK_Page_Down +ArrowRight,73,KEY_RIGHT_ARROW,0x4f,0xe04d,XK_Right +ArrowLeft,74,KEY_LEFT_ARROW,0x50,0xe04b,XK_Left +ArrowDown,75,KEY_DOWN_ARROW,0x51,0xe050,XK_Down +ArrowUp,76,KEY_UP_ARROW,0x52,0xe048,XK_Up +ControlLeft,77,KEY_LEFT_CTRL,^0x01,0x1d,XK_Control_L +ShiftLeft,78,KEY_LEFT_SHIFT,^0x02,0x2a,XK_Shift_L +AltLeft,79,KEY_LEFT_ALT,^0x04,0x38,XK_Alt_L +MetaLeft,80,KEY_LEFT_GUI,^0x08,0xe05b,XK_Meta_L +ControlRight,81,KEY_RIGHT_CTRL,^0x10,0xe01d,XK_Control_R +ShiftRight,82,KEY_RIGHT_SHIFT,^0x20,0x36,XK_Shift_R +AltRight,83,KEY_RIGHT_ALT,^0x40,0xe038,XK_Alt_R +MetaRight,84,KEY_RIGHT_GUI,^0x80,0xe05c,XK_Meta_R +Pause,85,KEY_PAUSE,0x48,0xe046,XK_Pause +ScrollLock,86,KEY_SCROLL_LOCK,0x47,0x46,XK_Scroll_Lock +NumLock,87,KEY_NUM_LOCK,0x53,0x45,XK_Num_Lock +ContextMenu,88,KEY_MENU,0x65,0xe05d,XK_Menu +NumpadDivide,89,KEYPAD_DIVIDE,0x54,0xe035,XK_KP_Divide +NumpadMultiply,90,KEYPAD_MULTIPLY,0x55,0x37,XK_multiply +NumpadSubtract,91,KEYPAD_SUBTRACT,0x56,0x4a,XK_KP_Subtract +NumpadAdd,92,KEYPAD_ADD,0x57,0x4e,XK_KP_Add +NumpadEnter,93,KEYPAD_ENTER,0x58,0xe01c,XK_KP_Enter +Numpad1,94,KEYPAD_1,0x59,0x4f,XK_KP_1 +Numpad2,95,KEYPAD_2,0x5a,0x50,XK_KP_2 +Numpad3,96,KEYPAD_3,0x5b,0x51,XK_KP_3 +Numpad4,97,KEYPAD_4,0x5c,0x4b,XK_KP_4 +Numpad5,98,KEYPAD_5,0x5d,0x4c,XK_KP_5 +Numpad6,99,KEYPAD_6,0x5e,0x4d,XK_KP_6 +Numpad7,100,KEYPAD_7,0x5f,0x47,XK_KP_7 +Numpad8,101,KEYPAD_8,0x60,0x48,XK_KP_8 +Numpad9,102,KEYPAD_9,0x61,0x49,XK_KP_9 +Numpad0,103,KEYPAD_0,0x62,0x52,XK_KP_0 +NumpadDecimal,104,KEYPAD_DOT,0x63,0x53,XK_KP_Decimal diff --git a/keymap.in b/keymap.in deleted file mode 100644 index b77f0f70..00000000 --- a/keymap.in +++ /dev/null @@ -1,136 +0,0 @@ -# ========================================================================== # -# # -# KVMD - The main Pi-KVM daemon. # -# # -# Copyright (C) 2018 Maxim Devaev <[email protected]> # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see <https://www.gnu.org/licenses/>. # -# # -# ========================================================================== # - - -# https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code/code_values -# https://github.com/NicoHood/HID/blob/master/src/KeyboardLayouts/ImprovedKeylayouts.h -# https://gist.github.com/MightyPork/6da26e382a7ad91b5496ee55fdc73db2 -# https://github.com/qemu/keycodemapdb/blob/master/data/keymaps.csv - -# ----------------------------------------------------------------------------------------------------------------------- -# Web | Serial code | Arduino key | OTG code (^ for mod) | AT set1 | X11 keysyms (^ for shift) -# ----------------------------------------------------------------------------------------------------------------------- -KeyA 1 KEY_A 0x04 0x1e ^XK_A,XK_a -KeyB 2 KEY_B 0x05 0x30 ^XK_B,XK_b -KeyC 3 KEY_C 0x06 0x2e ^XK_C,XK_c -KeyD 4 KEY_D 0x07 0x20 ^XK_D,XK_d -KeyE 5 KEY_E 0x08 0x12 ^XK_E,XK_e -KeyF 6 KEY_F 0x09 0x21 ^XK_F,XK_f -KeyG 7 KEY_G 0x0a 0x22 ^XK_G,XK_g -KeyH 8 KEY_H 0x0b 0x23 ^XK_H,XK_h -KeyI 9 KEY_I 0x0c 0x17 ^XK_I,XK_i -KeyJ 10 KEY_J 0x0d 0x24 ^XK_J,XK_j -KeyK 11 KEY_K 0x0e 0x25 ^XK_K,XK_k -KeyL 12 KEY_L 0x0f 0x26 ^XK_L,XK_l -KeyM 13 KEY_M 0x10 0x32 ^XK_M,XK_m -KeyN 14 KEY_N 0x11 0x31 ^XK_N,XK_n -KeyO 15 KEY_O 0x12 0x18 ^XK_O,XK_o -KeyP 16 KEY_P 0x13 0x19 ^XK_P,XK_p -KeyQ 17 KEY_Q 0x14 0x10 ^XK_Q,XK_q -KeyR 18 KEY_R 0x15 0x13 ^XK_R,XK_r -KeyS 19 KEY_S 0x16 0x1f ^XK_S,XK_s -KeyT 20 KEY_T 0x17 0x14 ^XK_T,XK_t -KeyU 21 KEY_U 0x18 0x16 ^XK_U,XK_u -KeyV 22 KEY_V 0x19 0x2f ^XK_V,XK_v -KeyW 23 KEY_W 0x1a 0x11 ^XK_W,XK_w -KeyX 24 KEY_X 0x1b 0x2d ^XK_X,XK_x -KeyY 25 KEY_Y 0x1c 0x15 ^XK_Y,XK_y -KeyZ 26 KEY_Z 0x1d 0x2c ^XK_Z,XK_z -Digit1 27 KEY_1 0x1e 0x02 XK_1,^XK_exclam -Digit2 28 KEY_2 0x1f 0x03 XK_2,^XK_at -Digit3 29 KEY_3 0x20 0x04 XK_3,^XK_numbersign -Digit4 30 KEY_4 0x21 0x05 XK_4,^XK_dollar -Digit5 31 KEY_5 0x22 0x06 XK_5,^XK_percent -Digit6 32 KEY_6 0x23 0x07 XK_6,^XK_asciicircum -Digit7 33 KEY_7 0x24 0x08 XK_7,^XK_ampersand -Digit8 34 KEY_8 0x25 0x09 XK_8,^XK_asterisk -Digit9 35 KEY_9 0x26 0x0a XK_9,^XK_parenleft -Digit0 36 KEY_0 0x27 0x0b XK_0,^XK_parenright -Enter 37 KEY_ENTER 0x28 0x1c XK_Return -Escape 38 KEY_ESC 0x29 0x01 XK_Escape -Backspace 39 KEY_BACKSPACE 0x2a 0x0e XK_BackSpace -Tab 40 KEY_TAB 0x2b 0x0f XK_Tab -Space 41 KEY_SPACE 0x2c 0x39 XK_space -Minus 42 KEY_MINUS 0x2d 0x0c XK_minus,^XK_underscore -Equal 43 KEY_EQUAL 0x2e 0x0d XK_equal,^XK_plus -BracketLeft 44 KEY_LEFT_BRACE 0x2f 0x1a XK_bracketleft,^XK_braceleft -BracketRight 45 KEY_RIGHT_BRACE 0x30 0x1b XK_bracketright,^XK_braceright -Backslash 46 KEY_BACKSLASH 0x31 0x2b XK_backslash,^XK_bar -Semicolon 47 KEY_SEMICOLON 0x33 0x27 XK_semicolon,^XK_colon -Quote 48 KEY_QUOTE 0x34 0x28 XK_apostrophe,^XK_quotedbl -Backquote 49 KEY_TILDE 0x35 0x29 XK_grave,^XK_asciitilde -Comma 50 KEY_COMMA 0x36 0x33 XK_comma,^XK_less -Period 51 KEY_PERIOD 0x37 0x34 XK_period,^XK_greater -Slash 52 KEY_SLASH 0x38 0x35 XK_slash,^XK_question -CapsLock 53 KEY_CAPS_LOCK 0x39 0x3a XK_Caps_Lock -F1 54 KEY_F1 0x3a 0x3b XK_F1 -F2 55 KEY_F2 0x3b 0x3c XK_F2 -F3 56 KEY_F3 0x3c 0x3d XK_F3 -F4 57 KEY_F4 0x3d 0x3e XK_F4 -F5 58 KEY_F5 0x3e 0x3f XK_F5 -F6 59 KEY_F6 0x3f 0x40 XK_F6 -F7 60 KEY_F7 0x40 0x41 XK_F7 -F8 61 KEY_F8 0x41 0x42 XK_F8 -F9 62 KEY_F9 0x42 0x43 XK_F9 -F10 63 KEY_F10 0x43 0x44 XK_F10 -F11 64 KEY_F11 0x44 0x57 XK_F11 -F12 65 KEY_F12 0x45 0x58 XK_F12 -PrintScreen 66 KEY_PRINT 0x46 0x54 XK_Sys_Req -Insert 67 KEY_INSERT 0x49 0xe052 XK_Insert -Home 68 KEY_HOME 0x4a 0xe047 XK_Home -PageUp 69 KEY_PAGE_UP 0x4b 0xe049 XK_Page_Up -Delete 70 KEY_DELETE 0x4c 0xe053 XK_Delete -End 71 KEY_END 0x4d 0xe04f XK_End -PageDown 72 KEY_PAGE_DOWN 0x4e 0xe051 XK_Page_Down -ArrowRight 73 KEY_RIGHT_ARROW 0x4f 0xe04d XK_Right -ArrowLeft 74 KEY_LEFT_ARROW 0x50 0xe04b XK_Left -ArrowDown 75 KEY_DOWN_ARROW 0x51 0xe050 XK_Down -ArrowUp 76 KEY_UP_ARROW 0x52 0xe048 XK_Up -ControlLeft 77 KEY_LEFT_CTRL ^0x01 0x1d XK_Control_L -ShiftLeft 78 KEY_LEFT_SHIFT ^0x02 0x2a XK_Shift_L -AltLeft 79 KEY_LEFT_ALT ^0x04 0x38 XK_Alt_L -MetaLeft 80 KEY_LEFT_GUI ^0x08 0xe05b XK_Meta_L -ControlRight 81 KEY_RIGHT_CTRL ^0x10 0xe01d XK_Control_R -ShiftRight 82 KEY_RIGHT_SHIFT ^0x20 0x36 XK_Shift_R -AltRight 83 KEY_RIGHT_ALT ^0x40 0xe038 XK_Alt_R -MetaRight 84 KEY_RIGHT_GUI ^0x80 0xe05c XK_Meta_R -Pause 85 KEY_PAUSE 0x48 0xe046 XK_Pause -ScrollLock 86 KEY_SCROLL_LOCK 0x47 0x46 XK_Scroll_Lock -NumLock 87 KEY_NUM_LOCK 0x53 0x45 XK_Num_Lock -ContextMenu 88 KEY_MENU 0x65 0xe05d XK_Menu -NumpadDivide 89 KEYPAD_DIVIDE 0x54 0xe035 XK_KP_Divide -NumpadMultiply 90 KEYPAD_MULTIPLY 0x55 0x37 XK_multiply -NumpadSubtract 91 KEYPAD_SUBTRACT 0x56 0x4a XK_KP_Subtract -NumpadAdd 92 KEYPAD_ADD 0x57 0x4e XK_KP_Add -NumpadEnter 93 KEYPAD_ENTER 0x58 0xe01c XK_KP_Enter -Numpad1 94 KEYPAD_1 0x59 0x4f XK_KP_1 -Numpad2 95 KEYPAD_2 0x5a 0x50 XK_KP_2 -Numpad3 96 KEYPAD_3 0x5b 0x51 XK_KP_3 -Numpad4 97 KEYPAD_4 0x5c 0x4b XK_KP_4 -Numpad5 98 KEYPAD_5 0x5d 0x4c XK_KP_5 -Numpad6 99 KEYPAD_6 0x5e 0x4d XK_KP_6 -Numpad7 100 KEYPAD_7 0x5f 0x47 XK_KP_7 -Numpad8 101 KEYPAD_8 0x60 0x48 XK_KP_8 -Numpad9 102 KEYPAD_9 0x61 0x49 XK_KP_9 -Numpad0 103 KEYPAD_0 0x62 0x52 XK_KP_0 -NumpadDecimal 104 KEYPAD_DOT 0x63 0x53 XK_KP_Decimal -# KEY_NON_US -# KEY_NON_US_NUM |