refactoring

This commit is contained in:
Maxim Devaev
2025-01-10 23:04:12 +02:00
parent 72c9ae3aa0
commit e7c06643b4
5 changed files with 26 additions and 12 deletions

View File

@@ -26,6 +26,7 @@ import struct
from ....keyboard.mappings import KEYMAP
from ....mouse import MouseRange
from ....mouse import MouseDelta
from .... import tools
from .... import bitbang
@@ -162,8 +163,8 @@ class MouseRelativeEvent(BaseEvent):
delta_y: int
def __post_init__(self) -> None:
assert -127 <= self.delta_x <= 127
assert -127 <= self.delta_y <= 127
assert MouseDelta.MIN <= self.delta_x <= MouseDelta.MAX
assert MouseDelta.MIN <= self.delta_y <= MouseDelta.MAX
def make_request(self) -> bytes:
return _make_request(struct.pack(">Bbbxx", 0x15, self.delta_x, self.delta_y))
@@ -175,8 +176,8 @@ class MouseWheelEvent(BaseEvent):
delta_y: int
def __post_init__(self) -> None:
assert -127 <= self.delta_x <= 127
assert -127 <= self.delta_y <= 127
assert MouseDelta.MIN <= self.delta_x <= MouseDelta.MAX
assert MouseDelta.MIN <= self.delta_y <= MouseDelta.MAX
def make_request(self) -> bytes:
# Горизонтальная прокрутка пока не поддерживается

View File

@@ -23,6 +23,7 @@
import math
from ....mouse import MouseRange
from ....mouse import MouseDelta
# =====
@@ -79,7 +80,7 @@ class Mouse: # pylint: disable=too-many-instance-attributes
def process_wheel(self, delta_x: int, delta_y: int) -> bytes:
_ = delta_x
assert -127 <= delta_y <= 127
assert MouseDelta.MIN <= delta_y <= MouseDelta.MAX
self.__wheel_y = (1 if delta_y > 0 else 255)
if not self.__absolute:
return self.__make_relative_cmd()
@@ -110,6 +111,6 @@ class Mouse: # pylint: disable=too-many-instance-attributes
])
def __fix_relative(self, value: int) -> int:
assert -127 <= value <= 127
assert MouseDelta.MIN <= value <= MouseDelta.MAX
value = math.ceil(value / 3)
return (value if value >= 0 else (255 + value))

View File

@@ -27,6 +27,7 @@ from ....keyboard.mappings import UsbKey
from ....keyboard.mappings import KEYMAP
from ....mouse import MouseRange
from ....mouse import MouseDelta
# =====
@@ -144,8 +145,8 @@ class MouseRelativeEvent(BaseEvent):
delta_y: int
def __post_init__(self) -> None:
assert -127 <= self.delta_x <= 127
assert -127 <= self.delta_y <= 127
assert MouseDelta.MIN <= self.delta_x <= MouseDelta.MAX
assert MouseDelta.MIN <= self.delta_y <= MouseDelta.MAX
@dataclasses.dataclass(frozen=True)
@@ -154,8 +155,8 @@ class MouseWheelEvent(BaseEvent):
delta_y: int
def __post_init__(self) -> None:
assert -127 <= self.delta_x <= 127
assert -127 <= self.delta_y <= 127
assert MouseDelta.MIN <= self.delta_x <= MouseDelta.MAX
assert MouseDelta.MIN <= self.delta_y <= MouseDelta.MAX
def make_mouse_report(