diff options
author | Devaev Maxim <[email protected]> | 2019-02-10 19:55:32 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2019-02-10 19:55:32 +0300 |
commit | afc4918f34d10440595caed8d35a9ca69df44cfd (patch) | |
tree | 01f958c14f467339dba04462121bb6e5f9fa64cd | |
parent | c8cdcaf51259388a2a476337e78e9bd7fbec8fcb (diff) |
improved genmap/keymap
-rwxr-xr-x | genmap.py | 27 | ||||
-rw-r--r-- | keymap.in | 218 |
2 files changed, 129 insertions, 116 deletions
@@ -1,34 +1,43 @@ #!/usr/bin/env python3 -import operator - -from typing import Tuple from typing import List +from typing import NamedTuple import yaml # ===== +class KeyMapping(NamedTuple): + kvmd_code: int + arduino_hid_key: str + js_key: str + + +# ===== def main() -> None: - keymap: List[Tuple[int, str, str]] = [] + keymap: List[KeyMapping] = [] with open("keymap.in") as keymap_file: for row in keymap_file: if not row.startswith("#"): parts = row.split() - keymap.append((int(parts[0]), parts[1], parts[2])) + keymap.append(KeyMapping( + kvmd_code=int(parts[0]), + arduino_hid_key=parts[1], + js_key=parts[2], + )) with open("kvmd/data/keymap.yaml", "w") as kvmd_yaml_file: yaml.dump({ - js_key: code - for (code, _, js_key) in sorted(keymap, key=operator.itemgetter(2)) + km.js_key: km.kvmd_code + for km in keymap }, kvmd_yaml_file, indent=4, default_flow_style=False) with open("hid/src/keymap.h", "w") as hid_header_file: hid_header_file.write("#pragma once\n\n#include <HID-Project.h>\n\n#include \"inline.h\"\n\n\n") hid_header_file.write("INLINE KeyboardKeycode keymap(uint8_t code) {\n\tswitch(code) {\n") - for (code, hid_key, _) in sorted(keymap, key=operator.itemgetter(1)): - hid_header_file.write("\t\tcase %d: return %s;\n" % (code, hid_key)) + for km in sorted(keymap, key=(lambda km: km.arduino_hid_key)): + hid_header_file.write("\t\tcase {km.kvmd_code}: return {km.arduino_hid_key};\n".format(km=km)) hid_header_file.write("\t\tdefault: return KEY_ERROR_UNDEFINED;\n\t}\n}\n") @@ -1,109 +1,113 @@ # https://github.com/NicoHood/HID/blob/master/src/HID-APIs/ImprovedKeylayouts.h # https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code -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 -# KEY_NON_US_NUM -# KEY_NUM_LOCK -# KEYPAD_DIVIDE -# KEYPAD_MULTIPLY -# KEYPAD_SUBTRACT -# KEYPAD_ADD -# KEYPAD_ENTER -# KEYPAD_1 -# KEYPAD_2 -# KEYPAD_3 -# KEYPAD_4 -# KEYPAD_5 -# KEYPAD_6 -# KEYPAD_7 -# KEYPAD_8 -# KEYPAD_9 -# KEYPAD_0 -# KEYPAD_DOT -# KEY_NON_US -# KEY_APPLICATION -# KEY_MENU +# +# ---------------------------------- +# 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 +# KEY_NON_US_NUM +# KEY_NUM_LOCK +# KEYPAD_DIVIDE +# KEYPAD_MULTIPLY +# KEYPAD_SUBTRACT +# KEYPAD_ADD +# KEYPAD_ENTER +# KEYPAD_1 +# KEYPAD_2 +# KEYPAD_3 +# KEYPAD_4 +# KEYPAD_5 +# KEYPAD_6 +# KEYPAD_7 +# KEYPAD_8 +# KEYPAD_9 +# KEYPAD_0 +# KEYPAD_DOT +# KEY_NON_US +# KEY_APPLICATION +# KEY_MENU |