using evdev instead of string constants

This commit is contained in:
Maxim Devaev
2025-05-01 03:03:25 +03:00
parent 1624b0cbf8
commit ebbd55ee17
29 changed files with 692 additions and 539 deletions

View File

@@ -168,10 +168,10 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
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.__queue_cmd(self.__keyboard.process_key(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.__queue_cmd(self.__mouse.process_button(button, state))
def _send_mouse_move_event(self, to_x: int, to_y: int) -> None:

View File

@@ -46,7 +46,7 @@ class Keyboard:
async def get_leds(self) -> dict[str, bool]:
return (await self.__leds.get())
def process_key(self, key: str, state: bool) -> bytes:
def process_key(self, key: int, state: bool) -> bytes:
code = KEYMAP[key].usb.code
is_modifier = KEYMAP[key].usb.is_modifier
if state:

View File

@@ -22,6 +22,8 @@
import math
from evdev import ecodes
from ....mouse import MouseRange
from ....mouse import MouseDelta
@@ -43,18 +45,18 @@ class Mouse: # pylint: disable=too-many-instance-attributes
def is_absolute(self) -> bool:
return self.__absolute
def process_button(self, button: str, state: bool) -> bytes:
def process_button(self, button: int, state: bool) -> bytes:
code = 0x00
match button:
case "left":
case ecodes.BTN_LEFT:
code = 0x01
case "right":
case ecodes.BTN_RIGHT:
code = 0x02
case "middle":
case ecodes.BTN_MIDDLE:
code = 0x04
case "up":
case ecodes.BTN_BACK:
code = 0x08
case "down":
case ecodes.BTN_FORWARD:
code = 0x10
if code:
if state: