diff options
-rw-r--r-- | hid/src/main.cpp | 3 | ||||
-rw-r--r-- | kvmd/kvmd/hid.py | 38 |
2 files changed, 26 insertions, 15 deletions
diff --git a/hid/src/main.cpp b/hid/src/main.cpp index 1a415a6f..31b45515 100644 --- a/hid/src/main.cpp +++ b/hid/src/main.cpp @@ -72,7 +72,6 @@ INLINE void cmdMouseWheelEvent() { // 2 bytes CMD_SERIAL.read(); // unused CMD_SERIAL.read(); // unused AbsoluteMouse.move(0, 0, delta_y); - CMD_SERIAL.println(delta_y); } @@ -81,6 +80,7 @@ void setup() { CMD_SERIAL.begin(CMD_SERIAL_SPEED); BootKeyboard.begin(); AbsoluteMouse.begin(); + CMD_SERIAL.write(0); } void loop() { @@ -93,5 +93,6 @@ void loop() { case 4: cmdMouseWheelEvent(); break; default: break; } + CMD_SERIAL.write(0); } } diff --git a/kvmd/kvmd/hid.py b/kvmd/kvmd/hid.py index 570ef4dc..ee683593 100644 --- a/kvmd/kvmd/hid.py +++ b/kvmd/kvmd/hid.py @@ -129,25 +129,35 @@ class Hid(multiprocessing.Process): except Exception: get_logger().exception("Can't execute emergency clear HID events") - def run(self) -> None: + def run(self) -> None: # pylint: disable=too-many-branches try: with serial.Serial(self.__device_path, self.__speed) as tty: + hid_ready = False while True: - try: - event = self.__queue.get(timeout=0.1) - except queue.Empty: - pass + if hid_ready: + try: + event = self.__queue.get(timeout=0.05) + except queue.Empty: + pass + else: + if isinstance(event, _KeyEvent): + self.__send_key_event(tty, event) + elif isinstance(event, _MouseMoveEvent): + self.__send_mouse_move_event(tty, event) + elif isinstance(event, _MouseButtonEvent): + self.__send_mouse_button_event(tty, event) + elif isinstance(event, _MouseWheelEvent): + self.__send_mouse_wheel_event(tty, event) + else: + raise RuntimeError("Unknown HID event") + hid_ready = False else: - if isinstance(event, _KeyEvent): - self.__send_key_event(tty, event) + if tty.in_waiting: + while tty.in_waiting: + tty.read(tty.in_waiting) + hid_ready = True + else: time.sleep(0.05) - elif isinstance(event, _MouseMoveEvent): - self.__send_mouse_move_event(tty, event) - elif isinstance(event, _MouseButtonEvent): - self.__send_mouse_button_event(tty, event) - time.sleep(0.05) - elif isinstance(event, _MouseWheelEvent): - self.__send_mouse_wheel_event(tty, event) if self.__stop_event.is_set() and self.__queue.qsize() == 0: break except Exception: |