"""Interactive Windows mouse diagnostic using only the fixture's Python. Run on the desktop, not Guest Control's Session 0. Ten accepted OK clicks finish the test; Cancel/Escape exits early. No settings or keystrokes are read. The adjacent .log contains changed mouse coordinates/buttons and dialog results. """ import ctypes from ctypes import wintypes import json from pathlib import Path import sys import threading import time if sys.platform != 'win32': raise SystemExit('Run this probe on the interactive Windows desktop.') user32 = ctypes.WinDLL('user32', use_last_error=True) user32.GetCursorPos.argtypes = [ctypes.POINTER(wintypes.POINT)] user32.GetCursorPos.restype = wintypes.BOOL user32.GetAsyncKeyState.argtypes = [ctypes.c_int] user32.GetAsyncKeyState.restype = ctypes.c_short user32.MessageBoxW.argtypes = [wintypes.HWND, wintypes.LPCWSTR, wintypes.LPCWSTR, wintypes.UINT] user32.MessageBoxW.restype = ctypes.c_int user32.SetProcessDPIAware.argtypes = [] user32.SetProcessDPIAware.restype = wintypes.BOOL user32.SetProcessDPIAware() log_path = Path(__file__).with_suffix('.log') stop = threading.Event() lock = threading.Lock() log = log_path.open('w', encoding='utf-8', buffering=1) def record(kind, **data): with lock: entry = json.dumps(dict(time=time.time(), kind=kind, **data)) log.write(entry + '\n') print(entry, flush=True) def monitor(): previous = None deadline = time.monotonic() + 600 point = wintypes.POINT() while not stop.is_set() and time.monotonic() < deadline: if user32.GetCursorPos(ctypes.byref(point)): state = (point.x, point.y, bool(user32.GetAsyncKeyState(1) & 0x8000), bool(user32.GetAsyncKeyState(2) & 0x8000)) if state != previous: record('windows_mouse', x=state[0], y=state[1], left=state[2], right=state[3]) previous = state stop.wait(0.01) record('monitor_finished') record('started', log=str(log_path)) worker = threading.Thread(target=monitor, daemon=True) worker.start() try: for accepted in range(10): result = user32.MessageBoxW( None, f'Accepted OK clicks: {accepted}\n\n' 'Use the physical mouse to click OK.\n' 'Each accepted click opens the next numbered test.\n' 'The count must advance on each ordinary click.\n\n' 'Cancel or Escape exits. No settings are changed.', 'RVBox Mouse Input Probe', 1) record('dialog_result', accepted_before=accepted, result=result) if result != 1: break finally: stop.set() worker.join(timeout=2) record('finished') log.close()