diff options
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/apps/kvmd/api/hid.py | 19 | ||||
-rw-r--r-- | kvmd/clients/kvmd.py | 4 |
2 files changed, 21 insertions, 2 deletions
diff --git a/kvmd/apps/kvmd/api/hid.py b/kvmd/apps/kvmd/api/hid.py index 8143deff..a2ea5d4c 100644 --- a/kvmd/apps/kvmd/api/hid.py +++ b/kvmd/apps/kvmd/api/hid.py @@ -154,6 +154,25 @@ class HidApi: # ===== + @exposed_ws(1) + async def __ws_bin_key_handler(self, _: WsSession, data: bytes) -> None: + try: + key = valid_hid_key(data[1:].decode("ascii")) + state = valid_bool(data[0]) + except Exception: + return + if key not in self.__ignore_keys: + self.__hid.send_key_events([(key, state)]) + + @exposed_ws(2) + async def __ws_bin_mouse_button_handler(self, _: WsSession, data: bytes) -> None: + try: + button = valid_hid_mouse_button(data[1:].decode("ascii")) + state = valid_bool(data[0]) + except Exception: + return + self.__hid.send_mouse_button_event(button, state) + @exposed_ws(3) async def __ws_bin_mouse_move_handler(self, _: WsSession, data: bytes) -> None: try: diff --git a/kvmd/clients/kvmd.py b/kvmd/clients/kvmd.py index ec86378d..569fb9d0 100644 --- a/kvmd/clients/kvmd.py +++ b/kvmd/clients/kvmd.py @@ -188,10 +188,10 @@ class KvmdClientWs: self.__communicated = False async def send_key_event(self, key: str, state: bool) -> None: - await self.__writer_queue.put(("key", {"key": key, "state": state})) + await self.__writer_queue.put(bytes([1, state]) + key.encode("ascii")) async def send_mouse_button_event(self, button: str, state: bool) -> None: - await self.__writer_queue.put(("mouse_button", {"button": button, "state": state})) + await self.__writer_queue.put(bytes([2, state]) + button.encode("ascii")) async def send_mouse_move_event(self, to_x: int, to_y: int) -> None: await self.__writer_queue.put(struct.pack(">bhh", 3, to_x, to_y)) |