from __future__ import annotations
from .core import AbstractMouseController, Coordinate, HoldMouseButton
try:
import pyautogui
except ImportError as e:
raise OSError("You need install windmouse[pyautogui]") from e
[docs]
class PyautoguiMouseController(AbstractMouseController):
"""
Mouse controller implementation using pyautogui.
"""
[docs]
def tick(self, step_duration: float = 0.1) -> bool:
coords = self._get_next_point()
if coords is None:
return False
pyautogui.moveTo(coords[0], coords[1], duration=step_duration)
return True
def _get_current_mouse_x(self) -> Coordinate:
return Coordinate(pyautogui.position().x)
def _get_current_mouse_y(self) -> Coordinate:
return Coordinate(pyautogui.position().y)
def _hold_mouse_button(self, button: HoldMouseButton) -> None:
pyautogui.mouseDown(button=button.value)
def _release_mouse_button(self, button: HoldMouseButton) -> None:
pyautogui.mouseUp(button=button.value)