diff options
author | Devaev Maxim <[email protected]> | 2020-05-22 21:07:54 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-05-22 21:07:54 +0300 |
commit | 43afd9acb3a7f2c94a3515f580ec3afcee720dc2 (patch) | |
tree | e1e3031ea1f083f17751c4997f29708dfb7e5d98 /kvmd/plugins | |
parent | 0fa0680bd7c28e246c70b5a5102e38a592bd0f0d (diff) |
server-side paste-as-keys
Diffstat (limited to 'kvmd/plugins')
-rw-r--r-- | kvmd/plugins/hid/__init__.py | 10 | ||||
-rw-r--r-- | kvmd/plugins/hid/otg/__init__.py | 10 | ||||
-rw-r--r-- | kvmd/plugins/hid/otg/device.py | 4 | ||||
-rw-r--r-- | kvmd/plugins/hid/otg/keyboard.py | 2 | ||||
-rw-r--r-- | kvmd/plugins/hid/otg/mouse.py | 2 | ||||
-rw-r--r-- | kvmd/plugins/hid/serial.py | 24 |
6 files changed, 31 insertions, 21 deletions
diff --git a/kvmd/plugins/hid/__init__.py b/kvmd/plugins/hid/__init__.py index bc391b03..5227d673 100644 --- a/kvmd/plugins/hid/__init__.py +++ b/kvmd/plugins/hid/__init__.py @@ -48,19 +48,19 @@ class BaseHid(BasePlugin): # ===== - async def send_key_event(self, key: str, state: bool) -> None: + def send_key_event(self, key: str, state: bool) -> None: raise NotImplementedError - async def send_mouse_button_event(self, button: str, state: bool) -> None: + def send_mouse_button_event(self, button: str, state: bool) -> None: raise NotImplementedError - async def send_mouse_move_event(self, to_x: int, to_y: int) -> None: + def send_mouse_move_event(self, to_x: int, to_y: int) -> None: raise NotImplementedError - async def send_mouse_wheel_event(self, delta_x: int, delta_y: int) -> None: + def send_mouse_wheel_event(self, delta_x: int, delta_y: int) -> None: raise NotImplementedError - async def clear_events(self) -> None: + def clear_events(self) -> None: raise NotImplementedError diff --git a/kvmd/plugins/hid/otg/__init__.py b/kvmd/plugins/hid/otg/__init__.py index 0684a674..3dc49c72 100644 --- a/kvmd/plugins/hid/otg/__init__.py +++ b/kvmd/plugins/hid/otg/__init__.py @@ -113,18 +113,18 @@ class Plugin(BaseHid): # ===== - async def send_key_event(self, key: str, state: bool) -> None: + def send_key_event(self, key: str, state: bool) -> None: self.__keyboard_proc.send_key_event(key, state) - async def send_mouse_button_event(self, button: str, state: bool) -> None: + def send_mouse_button_event(self, button: str, state: bool) -> None: self.__mouse_proc.send_button_event(button, state) - async def send_mouse_move_event(self, to_x: int, to_y: int) -> None: + def send_mouse_move_event(self, to_x: int, to_y: int) -> None: self.__mouse_proc.send_move_event(to_x, to_y) - async def send_mouse_wheel_event(self, delta_x: int, delta_y: int) -> None: + def send_mouse_wheel_event(self, delta_x: int, delta_y: int) -> None: self.__mouse_proc.send_wheel_event(delta_x, delta_y) - async def clear_events(self) -> None: + def clear_events(self) -> None: self.__keyboard_proc.send_clear_event() self.__mouse_proc.send_clear_event() diff --git a/kvmd/plugins/hid/otg/device.py b/kvmd/plugins/hid/otg/device.py index 2986ce4e..d1a2c86c 100644 --- a/kvmd/plugins/hid/otg/device.py +++ b/kvmd/plugins/hid/otg/device.py @@ -126,6 +126,10 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in def _queue_event(self, event: BaseEvent) -> None: self.__events_queue.put_nowait(event) + def _clear_queue(self) -> None: + while not self.__events_queue.empty(): + self.__events_queue.get_nowait() + def _ensure_write(self, report: bytes, reopen: bool=False, close: bool=False) -> bool: if reopen: self.__close_device() diff --git a/kvmd/plugins/hid/otg/keyboard.py b/kvmd/plugins/hid/otg/keyboard.py index fb964d8a..cb83232b 100644 --- a/kvmd/plugins/hid/otg/keyboard.py +++ b/kvmd/plugins/hid/otg/keyboard.py @@ -81,9 +81,11 @@ class KeyboardProcess(BaseDeviceProcess): self._ensure_write(b"\x00" * 8, close=True) # Release all keys and modifiers def send_clear_event(self) -> None: + self._clear_queue() self._queue_event(_ClearEvent()) def send_reset_event(self) -> None: + self._clear_queue() self._queue_event(_ResetEvent()) def send_key_event(self, key: str, state: bool) -> None: diff --git a/kvmd/plugins/hid/otg/mouse.py b/kvmd/plugins/hid/otg/mouse.py index a31d7ae5..3c41eb40 100644 --- a/kvmd/plugins/hid/otg/mouse.py +++ b/kvmd/plugins/hid/otg/mouse.py @@ -79,9 +79,11 @@ class MouseProcess(BaseDeviceProcess): self._ensure_write(report, close=True) # Release all buttons def send_clear_event(self) -> None: + self._clear_queue() self._queue_event(_ClearEvent()) def send_reset_event(self) -> None: + self._clear_queue() self._queue_event(_ResetEvent()) def send_button_event(self, button: str, state: bool) -> None: diff --git a/kvmd/plugins/hid/serial.py b/kvmd/plugins/hid/serial.py index 1725483b..f2ece19d 100644 --- a/kvmd/plugins/hid/serial.py +++ b/kvmd/plugins/hid/serial.py @@ -252,22 +252,24 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst # ===== - async def send_key_event(self, key: str, state: bool) -> None: - await self.__queue_event(_KeyEvent(key, state)) + def send_key_event(self, key: str, state: bool) -> None: + self.__queue_event(_KeyEvent(key, state)) - async def send_mouse_button_event(self, button: str, state: bool) -> None: - await self.__queue_event(_MouseButtonEvent(button, state)) + def send_mouse_button_event(self, button: str, state: bool) -> None: + self.__queue_event(_MouseButtonEvent(button, state)) - async def send_mouse_move_event(self, to_x: int, to_y: int) -> None: - await self.__queue_event(_MouseMoveEvent(to_x, to_y)) + def send_mouse_move_event(self, to_x: int, to_y: int) -> None: + self.__queue_event(_MouseMoveEvent(to_x, to_y)) - async def send_mouse_wheel_event(self, delta_x: int, delta_y: int) -> None: - await self.__queue_event(_MouseWheelEvent(delta_x, delta_y)) + def send_mouse_wheel_event(self, delta_x: int, delta_y: int) -> None: + self.__queue_event(_MouseWheelEvent(delta_x, delta_y)) - async def clear_events(self) -> None: - await self.__queue_event(_ClearEvent()) + def clear_events(self) -> None: + while not self.__events_queue.empty(): + self.__events_queue.get_nowait() + self.__queue_event(_ClearEvent()) - async def __queue_event(self, event: _BaseEvent) -> None: + def __queue_event(self, event: _BaseEvent) -> None: if not self.__stop_event.is_set(): self.__events_queue.put_nowait(event) |