diff options
author | Devaev Maxim <[email protected]> | 2018-08-20 00:57:55 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2018-08-20 00:57:55 +0300 |
commit | 49b83948c0a41bb807be716a866b02a5c4124833 (patch) | |
tree | d5bf3c3d8b807e48e9d63778179522767cb57227 /kvmd | |
parent | 61f7db14a8ee49623d6a01a81f40957e086a0187 (diff) |
two-way communication between hid and kvmd
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/kvmd/hid.py | 38 |
1 files changed, 24 insertions, 14 deletions
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: |