mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 09:10:30 +08:00
improved jiggler logic
This commit is contained in:
parent
05bced1461
commit
72c9ae3aa0
@ -32,3 +32,7 @@ class MouseRange:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def remap(cls, value: int, out_min: int, out_max: int) -> int:
|
def remap(cls, value: int, out_min: int, out_max: int) -> int:
|
||||||
return tools.remap(value, cls.MIN, cls.MAX, out_min, out_max)
|
return tools.remap(value, cls.MIN, cls.MAX, out_min, out_max)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def normalize(cls, value: int) -> int:
|
||||||
|
return min(max(cls.MIN, value), cls.MAX)
|
||||||
|
|||||||
@ -65,11 +65,13 @@ class BaseHid(BasePlugin): # pylint: disable=too-many-instance-attributes
|
|||||||
self.__mouse_x_range = (mouse_x_min, mouse_x_max)
|
self.__mouse_x_range = (mouse_x_min, mouse_x_max)
|
||||||
self.__mouse_y_range = (mouse_y_min, mouse_y_max)
|
self.__mouse_y_range = (mouse_y_min, mouse_y_max)
|
||||||
|
|
||||||
self.__jiggler_enabled = jiggler_enabled
|
self.__j_enabled = jiggler_enabled
|
||||||
self.__jiggler_active = jiggler_active
|
self.__j_active = jiggler_active
|
||||||
self.__jiggler_interval = jiggler_interval
|
self.__j_interval = jiggler_interval
|
||||||
self.__jiggler_absolute = True
|
self.__j_absolute = True
|
||||||
self.__activity_ts = 0
|
self.__j_activity_ts = 0
|
||||||
|
self.__j_last_x = 0
|
||||||
|
self.__j_last_y = 0
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_base_options(cls) -> dict[str, Any]:
|
def _get_base_options(cls) -> dict[str, Any]:
|
||||||
@ -174,6 +176,8 @@ class BaseHid(BasePlugin): # pylint: disable=too-many-instance-attributes
|
|||||||
# =====
|
# =====
|
||||||
|
|
||||||
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.__j_last_x = to_x
|
||||||
|
self.__j_last_y = to_y
|
||||||
if self.__mouse_x_range != MouseRange.RANGE:
|
if self.__mouse_x_range != MouseRange.RANGE:
|
||||||
to_x = MouseRange.remap(to_x, *self.__mouse_x_range)
|
to_x = MouseRange.remap(to_x, *self.__mouse_x_range)
|
||||||
if self.__mouse_y_range != MouseRange.RANGE:
|
if self.__mouse_y_range != MouseRange.RANGE:
|
||||||
@ -242,36 +246,37 @@ class BaseHid(BasePlugin): # pylint: disable=too-many-instance-attributes
|
|||||||
handler(*xy)
|
handler(*xy)
|
||||||
|
|
||||||
def __bump_activity(self) -> None:
|
def __bump_activity(self) -> None:
|
||||||
self.__activity_ts = int(time.monotonic())
|
self.__j_activity_ts = int(time.monotonic())
|
||||||
|
|
||||||
def _set_jiggler_absolute(self, absolute: bool) -> None:
|
def _set_jiggler_absolute(self, absolute: bool) -> None:
|
||||||
self.__jiggler_absolute = absolute
|
self.__j_absolute = absolute
|
||||||
|
|
||||||
def _set_jiggler_active(self, active: bool) -> None:
|
def _set_jiggler_active(self, active: bool) -> None:
|
||||||
if self.__jiggler_enabled:
|
if self.__j_enabled:
|
||||||
self.__jiggler_active = active
|
self.__j_active = active
|
||||||
|
|
||||||
def _get_jiggler_state(self) -> dict:
|
def _get_jiggler_state(self) -> dict:
|
||||||
return {
|
return {
|
||||||
"jiggler": {
|
"jiggler": {
|
||||||
"enabled": self.__jiggler_enabled,
|
"enabled": self.__j_enabled,
|
||||||
"active": self.__jiggler_active,
|
"active": self.__j_active,
|
||||||
"interval": self.__jiggler_interval,
|
"interval": self.__j_interval,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
|
|
||||||
async def systask(self) -> None:
|
async def systask(self) -> None:
|
||||||
factor = 1
|
|
||||||
while True:
|
while True:
|
||||||
if self.__jiggler_active and (self.__activity_ts + self.__jiggler_interval < int(time.monotonic())):
|
if self.__j_active and (self.__j_activity_ts + self.__j_interval < int(time.monotonic())):
|
||||||
for _ in range(5):
|
if self.__j_absolute:
|
||||||
if self.__jiggler_absolute:
|
(x, y) = (self.__j_last_x, self.__j_last_y)
|
||||||
self.send_mouse_move_event(100 * factor, 100 * factor)
|
for move in [100, -100, 100, -100, 0]:
|
||||||
|
self.send_mouse_move_event(MouseRange.normalize(x + move), MouseRange.normalize(y + move))
|
||||||
|
await asyncio.sleep(0.1)
|
||||||
else:
|
else:
|
||||||
self.send_mouse_relative_event(10 * factor, 10 * factor)
|
for move in [10, -10, 10, -10]:
|
||||||
factor *= -1
|
self.send_mouse_relative_event(move, move)
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user