mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-31 18:11:54 +08:00
using evdev instead of string constants
This commit is contained in:
@@ -206,10 +206,10 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
|
||||
self._set_jiggler_active(jiggler)
|
||||
self.__notifier.notify()
|
||||
|
||||
def _send_key_event(self, key: str, state: bool) -> None:
|
||||
def _send_key_event(self, key: int, state: bool) -> None:
|
||||
self.__keyboard_proc.send_key_event(key, state)
|
||||
|
||||
def _send_mouse_button_event(self, button: str, state: bool) -> None:
|
||||
def _send_mouse_button_event(self, button: int, state: bool) -> None:
|
||||
self.__mouse_current.send_button_event(button, state)
|
||||
|
||||
def _send_mouse_move_event(self, to_x: int, to_y: int) -> None:
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
import struct
|
||||
import dataclasses
|
||||
|
||||
from evdev import ecodes
|
||||
|
||||
from ....keyboard.mappings import UsbKey
|
||||
from ....keyboard.mappings import KEYMAP
|
||||
|
||||
@@ -46,7 +48,7 @@ class ResetEvent(BaseEvent):
|
||||
# =====
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class KeyEvent(BaseEvent):
|
||||
key: UsbKey
|
||||
key: UsbKey
|
||||
state: bool
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
@@ -56,13 +58,13 @@ class KeyEvent(BaseEvent):
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class ModifierEvent(BaseEvent):
|
||||
modifier: UsbKey
|
||||
state: bool
|
||||
state: bool
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
assert self.modifier.is_modifier
|
||||
|
||||
|
||||
def make_keyboard_event(key: str, state: bool) -> (KeyEvent | ModifierEvent):
|
||||
def make_keyboard_event(key: int, state: bool) -> (KeyEvent | ModifierEvent):
|
||||
usb_key = KEYMAP[key].usb
|
||||
if usb_key.is_modifier:
|
||||
return ModifierEvent(usb_key, state)
|
||||
@@ -102,17 +104,17 @@ def make_keyboard_report(
|
||||
# =====
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class MouseButtonEvent(BaseEvent):
|
||||
button: str
|
||||
state: bool
|
||||
code: int = 0
|
||||
button: int
|
||||
state: bool
|
||||
code: int = 0
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
object.__setattr__(self, "code", {
|
||||
"left": 0x1,
|
||||
"right": 0x2,
|
||||
"middle": 0x4,
|
||||
"up": 0x8, # Back
|
||||
"down": 0x10, # Forward
|
||||
ecodes.BTN_LEFT: 0x1,
|
||||
ecodes.BTN_RIGHT: 0x2,
|
||||
ecodes.BTN_MIDDLE: 0x4,
|
||||
ecodes.BTN_BACK: 0x8, # Back/Up
|
||||
ecodes.BTN_FORWARD: 0x10, # Forward/Down
|
||||
}[self.button])
|
||||
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class KeyboardProcess(BaseDeviceProcess):
|
||||
self._clear_queue()
|
||||
self._queue_event(ResetEvent())
|
||||
|
||||
def send_key_event(self, key: str, state: bool) -> None:
|
||||
def send_key_event(self, key: int, state: bool) -> None:
|
||||
self._queue_event(make_keyboard_event(key, state))
|
||||
|
||||
# =====
|
||||
|
||||
@@ -85,7 +85,7 @@ class MouseProcess(BaseDeviceProcess):
|
||||
self._clear_queue()
|
||||
self._queue_event(ResetEvent())
|
||||
|
||||
def send_button_event(self, button: str, state: bool) -> None:
|
||||
def send_button_event(self, button: int, state: bool) -> None:
|
||||
self._queue_event(MouseButtonEvent(button, state))
|
||||
|
||||
def send_move_event(self, to_x: int, to_y: int) -> None:
|
||||
|
||||
Reference in New Issue
Block a user