mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 09:01:54 +08:00
server-side paste-as-keys
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user