# ScreenWatch [![tests](https://github.com/abnsapkota001/screenwatch/actions/workflows/tests.yml/badge.svg)](https://github.com/abnsapkota001/screenwatch/actions/workflows/tests.yml) ScreenWatch detects persistent visual state changes in desktop applications. It is useful when a legacy application, remote desktop, dashboard, or long-running workflow has no API or notification hook. > Give notifications to software that does not have notifications. ![ScreenWatch detecting a real desktop state change](docs/assets/screenwatch-demo.gif) ## Install ScreenWatch requires Python 3.10 or newer. ```powershell py -m venv .venv .\.venv\Scripts\Activate.ps1 python -m pip install -e ".[dev]" ``` Verify a fresh installation without capturing the desktop: ```powershell python examples\synthetic_change.py ``` ## Watch a real application ```powershell screenwatch select ` --threshold 0.03 ` --settle 0.75 ` --save-diff demo-output ` --save-frames ` --once ``` Drag a tight rectangle around the status you care about and press Enter. The command exits after a persistent change and saves the before, after, and heatmap images. Press Escape to cancel selection. Because the score is averaged across the selected region, a small text change inside a large rectangle may need a lower threshold. `0.03`–`0.05` is a useful starting range for text; tune it for the target UI. ## Python API ```python from screenwatch import ChangeEvent, Watcher def notify(event: ChangeEvent) -> None: print(f"change={event.score:.2%} boxes={event.boxes}") event.save_diff("change.png") with Watcher.select_region(interval=0.5) as watcher: watcher.on_change(threshold=0.03, callback=notify, executor="thread") event = watcher.wait_until_change(timeout=300) ``` Explicit regions use absolute `(left, top, right, bottom)` desktop coordinates: ```python watcher = Watcher(region=(500, 200, 900, 600)) watcher.ignore((520, 220, 620, 260)) ``` See [the behavioral contract](docs/behavior.md) for baseline, re-arming, score, coordinate, event ownership, timeout, and callback guarantees. ## Architecture ```text MSS capture → ignore mask → Detector → persistence gate → ChangeEvent │ ├─ callback └─ score, heatmap, boxes └─ save artifacts ``` - `watcher.py` manages capture, stabilization, baseline transitions, and callbacks. - `detectors.py` contains the detector interface and default SSIM implementation. - `cli.py` is a thin command-line client of the public API. The detector boundary allows a future OCR backend without changing capture or lifecycle behavior. OCR is roadmap work, not part of v0.1. ## Quality checks ```powershell python -m ruff check . python -m mypy python -m pytest -m "not integration" python benchmarks\benchmark_detector.py --iterations 100 ``` Reference run on September 5, 2026: Python 3.13, Windows 10.0.26200, AMD Ryzen 5 5500U, 1280×720 frames, 25 iterations. Mean detector latency was 158.01 ms; the known-change score was 0.086555 and maximum low-amplitude synthetic-noise score was 0.000220. These are local measurements, not cross-platform promises. Unit tests use synthetic NumPy frames. The capture integration test requires a real graphical desktop and is deliberately opt-in: ```powershell $env:SCREENWATCH_RUN_CAPTURE = "1" python -m pytest -m integration ``` GitHub Actions runs Ruff, mypy, and unit tests on Windows, macOS, and Linux with Python 3.10 and 3.13. Real desktop capture is not claimed to run in headless CI. ## Privacy ScreenWatch has no networking, telemetry, analytics, or upload code. Screenshots remain local and in memory unless the caller uses an artifact save method or a CLI save option. ## Limitations - v0.1 detects visual change; it does not understand whether text says “Complete” or “Error.” - Thresholds are target-specific and may require tuning. - Animated content and blinking cursors should be tightly cropped or ignored. - Region selection requires a graphical desktop and OS screen-capture permission. - Moving or resizing the target window invalidates hard-coded coordinates. - Headless CI verifies detector logic, not interactive desktop capture. ## License MIT