from __future__ import annotations import ctypes import time from dataclasses import dataclass @dataclass(frozen=True, slots=True) class ClickResult: ok: bool message: str user32 = ctypes.windll.user32 MOUSEEVENTF_LEFTDOWN = 0x0002 MOUSEEVENTF_LEFTUP = 0x0004 MOUSEEVENTF_RIGHTDOWN = 0x0008 MOUSEEVENTF_RIGHTUP = 0x0010 def click(button: str = "left", count: int = 1, interval: float = 0.05) -> ClickResult: b = (button or "left").strip().lower() c = max(1, min(1000, int(count))) iv = max(0.0, min(5.0, float(interval))) down_up = (MOUSEEVENTF_LEFTDOWN, MOUSEEVENTF_LEFTUP) if b != "right" else (MOUSEEVENTF_RIGHTDOWN, MOUSEEVENTF_RIGHTUP) try: for _ in range(c): user32.mouse_event(down_up[0], 0, 0, 0, 0) user32.mouse_event(down_up[1], 0, 0, 0, 0) if iv: time.sleep(iv) return ClickResult(True, f"Clicked {b} x{c}.") except Exception as e: return ClickResult(False, f"Click failed: {e}")