summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2019-09-26 04:23:50 +0300
committerDevaev Maxim <[email protected]>2019-09-26 04:23:50 +0300
commit5e1e3cdf640face90ac5898ea4de7484c5edeae1 (patch)
tree71997b466302594a43929076a817b5748927512e /kvmd
parent2f767573d301dbc2b9403363a71ff7acf38049b4 (diff)
refactoring
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/data/keymap.yaml108
-rw-r--r--kvmd/keymap.py103
-rw-r--r--kvmd/keymap.py.mako (renamed from kvmd/data/keymap.yaml.mako)21
-rw-r--r--kvmd/plugins/hid/serial.py2
4 files changed, 118 insertions, 116 deletions
diff --git a/kvmd/data/keymap.yaml b/kvmd/data/keymap.yaml
deleted file mode 100644
index 4981b5ff..00000000
--- a/kvmd/data/keymap.yaml
+++ /dev/null
@@ -1,108 +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/>. #
-# #
-# ========================================================================== #
-
-
-AltLeft: 79
-AltRight: 83
-ArrowDown: 75
-ArrowLeft: 74
-ArrowRight: 73
-ArrowUp: 76
-Backquote: 49
-Backslash: 46
-Backspace: 39
-BracketLeft: 44
-BracketRight: 45
-CapsLock: 53
-Comma: 50
-ControlLeft: 77
-ControlRight: 81
-Delete: 70
-Digit0: 36
-Digit1: 27
-Digit2: 28
-Digit3: 29
-Digit4: 30
-Digit5: 31
-Digit6: 32
-Digit7: 33
-Digit8: 34
-Digit9: 35
-End: 71
-Enter: 37
-Equal: 43
-Escape: 38
-F1: 54
-F10: 63
-F11: 64
-F12: 65
-F2: 55
-F3: 56
-F4: 57
-F5: 58
-F6: 59
-F7: 60
-F8: 61
-F9: 62
-Home: 68
-Insert: 67
-KeyA: 1
-KeyB: 2
-KeyC: 3
-KeyD: 4
-KeyE: 5
-KeyF: 6
-KeyG: 7
-KeyH: 8
-KeyI: 9
-KeyJ: 10
-KeyK: 11
-KeyL: 12
-KeyM: 13
-KeyN: 14
-KeyO: 15
-KeyP: 16
-KeyQ: 17
-KeyR: 18
-KeyS: 19
-KeyT: 20
-KeyU: 21
-KeyV: 22
-KeyW: 23
-KeyX: 24
-KeyY: 25
-KeyZ: 26
-MetaLeft: 80
-MetaRight: 84
-Minus: 42
-PageDown: 72
-PageUp: 69
-Pause: 85
-Period: 51
-PrintScreen: 66
-Quote: 48
-ScrollLock: 86
-Semicolon: 47
-ShiftLeft: 78
-ShiftRight: 82
-Slash: 52
-Space: 41
-Tab: 40
diff --git a/kvmd/keymap.py b/kvmd/keymap.py
index e6dfecbb..be32bae2 100644
--- a/kvmd/keymap.py
+++ b/kvmd/keymap.py
@@ -20,17 +20,108 @@
# ========================================================================== #
-import pkgutil
+import dataclasses
from typing import Dict
-import yaml
-
# =====
-def _get_keymap() -> Dict[str, int]:
- return yaml.safe_load(pkgutil.get_data("kvmd", "data/keymap.yaml").decode()) # type: ignore
[email protected](frozen=True)
+class SerialKey:
+ code: int
+
+
[email protected](frozen=True)
+class Key:
+ serial: SerialKey
# =====
-KEYMAP = _get_keymap()
+KEYMAP: Dict[str, Key] = {
+ "AltLeft": Key(serial=SerialKey(code=79)),
+ "AltRight": Key(serial=SerialKey(code=83)),
+ "ArrowDown": Key(serial=SerialKey(code=75)),
+ "ArrowLeft": Key(serial=SerialKey(code=74)),
+ "ArrowRight": Key(serial=SerialKey(code=73)),
+ "ArrowUp": Key(serial=SerialKey(code=76)),
+ "Backquote": Key(serial=SerialKey(code=49)),
+ "Backslash": Key(serial=SerialKey(code=46)),
+ "Backspace": Key(serial=SerialKey(code=39)),
+ "BracketLeft": Key(serial=SerialKey(code=44)),
+ "BracketRight": Key(serial=SerialKey(code=45)),
+ "CapsLock": Key(serial=SerialKey(code=53)),
+ "Comma": Key(serial=SerialKey(code=50)),
+ "ControlLeft": Key(serial=SerialKey(code=77)),
+ "ControlRight": Key(serial=SerialKey(code=81)),
+ "Delete": Key(serial=SerialKey(code=70)),
+ "Digit0": Key(serial=SerialKey(code=36)),
+ "Digit1": Key(serial=SerialKey(code=27)),
+ "Digit2": Key(serial=SerialKey(code=28)),
+ "Digit3": Key(serial=SerialKey(code=29)),
+ "Digit4": Key(serial=SerialKey(code=30)),
+ "Digit5": Key(serial=SerialKey(code=31)),
+ "Digit6": Key(serial=SerialKey(code=32)),
+ "Digit7": Key(serial=SerialKey(code=33)),
+ "Digit8": Key(serial=SerialKey(code=34)),
+ "Digit9": Key(serial=SerialKey(code=35)),
+ "End": Key(serial=SerialKey(code=71)),
+ "Enter": Key(serial=SerialKey(code=37)),
+ "Equal": Key(serial=SerialKey(code=43)),
+ "Escape": Key(serial=SerialKey(code=38)),
+ "F1": Key(serial=SerialKey(code=54)),
+ "F10": Key(serial=SerialKey(code=63)),
+ "F11": Key(serial=SerialKey(code=64)),
+ "F12": Key(serial=SerialKey(code=65)),
+ "F2": Key(serial=SerialKey(code=55)),
+ "F3": Key(serial=SerialKey(code=56)),
+ "F4": Key(serial=SerialKey(code=57)),
+ "F5": Key(serial=SerialKey(code=58)),
+ "F6": Key(serial=SerialKey(code=59)),
+ "F7": Key(serial=SerialKey(code=60)),
+ "F8": Key(serial=SerialKey(code=61)),
+ "F9": Key(serial=SerialKey(code=62)),
+ "Home": Key(serial=SerialKey(code=68)),
+ "Insert": Key(serial=SerialKey(code=67)),
+ "KeyA": Key(serial=SerialKey(code=1)),
+ "KeyB": Key(serial=SerialKey(code=2)),
+ "KeyC": Key(serial=SerialKey(code=3)),
+ "KeyD": Key(serial=SerialKey(code=4)),
+ "KeyE": Key(serial=SerialKey(code=5)),
+ "KeyF": Key(serial=SerialKey(code=6)),
+ "KeyG": Key(serial=SerialKey(code=7)),
+ "KeyH": Key(serial=SerialKey(code=8)),
+ "KeyI": Key(serial=SerialKey(code=9)),
+ "KeyJ": Key(serial=SerialKey(code=10)),
+ "KeyK": Key(serial=SerialKey(code=11)),
+ "KeyL": Key(serial=SerialKey(code=12)),
+ "KeyM": Key(serial=SerialKey(code=13)),
+ "KeyN": Key(serial=SerialKey(code=14)),
+ "KeyO": Key(serial=SerialKey(code=15)),
+ "KeyP": Key(serial=SerialKey(code=16)),
+ "KeyQ": Key(serial=SerialKey(code=17)),
+ "KeyR": Key(serial=SerialKey(code=18)),
+ "KeyS": Key(serial=SerialKey(code=19)),
+ "KeyT": Key(serial=SerialKey(code=20)),
+ "KeyU": Key(serial=SerialKey(code=21)),
+ "KeyV": Key(serial=SerialKey(code=22)),
+ "KeyW": Key(serial=SerialKey(code=23)),
+ "KeyX": Key(serial=SerialKey(code=24)),
+ "KeyY": Key(serial=SerialKey(code=25)),
+ "KeyZ": Key(serial=SerialKey(code=26)),
+ "MetaLeft": Key(serial=SerialKey(code=80)),
+ "MetaRight": Key(serial=SerialKey(code=84)),
+ "Minus": Key(serial=SerialKey(code=42)),
+ "PageDown": Key(serial=SerialKey(code=72)),
+ "PageUp": Key(serial=SerialKey(code=69)),
+ "Pause": Key(serial=SerialKey(code=85)),
+ "Period": Key(serial=SerialKey(code=51)),
+ "PrintScreen": Key(serial=SerialKey(code=66)),
+ "Quote": Key(serial=SerialKey(code=48)),
+ "ScrollLock": Key(serial=SerialKey(code=86)),
+ "Semicolon": Key(serial=SerialKey(code=47)),
+ "ShiftLeft": Key(serial=SerialKey(code=78)),
+ "ShiftRight": Key(serial=SerialKey(code=82)),
+ "Slash": Key(serial=SerialKey(code=52)),
+ "Space": Key(serial=SerialKey(code=41)),
+ "Tab": Key(serial=SerialKey(code=40)),
+}
diff --git a/kvmd/data/keymap.yaml.mako b/kvmd/keymap.py.mako
index 820c0027..06b0c7d9 100644
--- a/kvmd/data/keymap.yaml.mako
+++ b/kvmd/keymap.py.mako
@@ -19,7 +19,26 @@
# #
# ========================================================================== #
+
+import dataclasses
+
+from typing import Dict
+
+
+# =====
[email protected](frozen=True)
+class SerialKey:
+ code: int
+
+
[email protected](frozen=True)
+class Key:
+ serial: SerialKey
+
<%! import operator %>
+# =====
+KEYMAP: Dict[str, Key] = {
% for km in sorted(keymap, key=operator.attrgetter("web_key")):
-${km.web_key}: ${km.arduino_hid_code}
+ "${km.web_key}": Key(serial=SerialKey(code=${km.serial_hid_code})),
% endfor
+}
diff --git a/kvmd/plugins/hid/serial.py b/kvmd/plugins/hid/serial.py
index 7b7c4275..5b78e5a9 100644
--- a/kvmd/plugins/hid/serial.py
+++ b/kvmd/plugins/hid/serial.py
@@ -82,7 +82,7 @@ class _KeyEvent(_BoolEvent):
assert self.name in keymap.KEYMAP
def make_command(self) -> bytes:
- code = keymap.KEYMAP[self.name]
+ code = keymap.KEYMAP[self.name].serial.code
key_bytes = bytes([code])
assert len(key_bytes) == 1, (self, key_bytes, code)
state_bytes = (b"\x01" if self.state else b"\x00")