diff options
author | Devaev Maxim <[email protected]> | 2018-07-09 20:37:43 +0000 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2018-07-09 20:37:43 +0000 |
commit | c63e5a39abcb96dc9af56e91f25b7da266d681b2 (patch) | |
tree | d95654c5dec3e54f23a0310faf87985c30446da1 | |
parent | 2485f8e54800009ff63324a51e45d28f9a80527c (diff) |
js key -> ps2 keycodes
-rw-r--r-- | kvmd/kvmd/ps2.py | 56 | ||||
-rw-r--r-- | kvmd/tox.ini | 3 |
2 files changed, 57 insertions, 2 deletions
diff --git a/kvmd/kvmd/ps2.py b/kvmd/kvmd/ps2.py index 0820c13b..84e51fcf 100644 --- a/kvmd/kvmd/ps2.py +++ b/kvmd/kvmd/ps2.py @@ -20,11 +20,65 @@ class _KeyEvent(NamedTuple): def _key_event_to_ps2_codes(event: _KeyEvent) -> List[int]: + # https://techdocs.altium.com/display/FPGA/PS2+Keyboard+Scan+Codes + # http://www.vetra.com/scancodes.html + get_logger().info(str(event)) - return [] # TODO + + if event.key == "PrintScreen": + return ([0xE0, 0x12, 0xE0, 0x7C] if event.state else [0xE0, 0xF0, 0x7C, 0xE0, 0xF0, 0x12]) + # TODO: pause/break + else: + codes = { + "Escape": [0x76], "Backspace": [0x66], + "Tab": [0x0D], "Enter": [0x5A], + "Insert": [0xE0, 0x70], "Delete": [0xE0, 0x71], + "Home": [0xE0, 0x6C], "End": [0xE0, 0x69], + "PageUp": [0xE0, 0x7D], "PageDown": [0xE0, 0x7A], + "ArrowLeft": [0xE0, 0x6B], "ArrowRight": [0xE0, 0x74], + "ArrowUp": [0xE0, 0x75], "ArrowDown": [0xE0, 0x72], + + "CapsLock": [0x58], + "ScrollLock": [0x7E], "NumLock": [0x77], + "ShiftLeft": [0x12], "ShiftRight": [0x59], + "ControlLeft": [0x14], "ControlRight": [0xE0, 0x14], + "AltLeft": [0x11], "AltRight": [0xE0, 0x11], + "MetaLeft": [0xE0, 0x1F], "MetaRight": [0xE0, 0x27], + + "Backquote": [0x0E], "Minus": [0x4E], "Equal": [0x55], "Space": [0x29], + "BracketLeft": [0x54], "BracketRight": [0x5B], "Semicolon": [0x4C], "Quote": [0x52], + "Comma": [0x41], "Period": [0x49], "Slash": [0x4A], "Backslash": [0x5D], + + "Digit1": [0x16], "Digit2": [0x1E], "Digit3": [0x26], "Digit4": [0x25], "Digit5": [0x2E], + "Digit6": [0x36], "Digit7": [0x3D], "Digit8": [0x3E], "Digit9": [0x46], "Digit0": [0x45], + + "KeyQ": [0x15], "KeyW": [0x1D], "KeyE": [0x24], "KeyR": [0x2D], "KeyT": [0x2C], + "KeyY": [0x35], "KeyU": [0x3C], "KeyI": [0x43], "KeyO": [0x44], "KeyP": [0x4D], + "KeyA": [0x1C], "KeyS": [0x1B], "KeyD": [0x23], "KeyF": [0x2B], "KeyG": [0x34], + "KeyH": [0x33], "KeyJ": [0x3B], "KeyK": [0x42], "KeyL": [0x4B], "KeyZ": [0x1A], + "KeyX": [0x22], "KeyC": [0x21], "KeyV": [0x2A], "KeyB": [0x32], "KeyN": [0x31], + "KeyM": [0x3A], + + "F1": [0x05], "F2": [0x06], "F3": [0x04], "F4": [0x0C], + "F5": [0x03], "F6": [0x0B], "F7": [0x83], "F8": [0x0A], + "F9": [0x01], "F10": [0x09], "F11": [0x78], "F12": [0x07], + + # TODO: keypad + }.get(event.key, []) + if codes: + if not event.state: + assert 1 <= len(codes) <= 2, (event, codes) + if len(codes) == 1: + codes = [0xF0, codes[0]] + elif len(codes) == 2: + codes = [codes[0], 0xF0, codes[1]] + return codes + return [] class Ps2Keyboard(multiprocessing.Process): + # http://dkudrow.blogspot.com/2013/08/ps2-keyboard-emulation-with-arduino-uno.html + def __init__(self, clock: int, data: int, pulse: float) -> None: super().__init__(daemon=True) diff --git a/kvmd/tox.ini b/kvmd/tox.ini index 18c839f2..ae90a7af 100644 --- a/kvmd/tox.ini +++ b/kvmd/tox.ini @@ -34,4 +34,5 @@ deps = max-line-length = 160 # W503 line break before binary operator # E227 missing whitespace around bitwise or shift operator -ignore=W503,E227 +# E241 multiple spaces after +ignore=W503,E227,E241 |