Skip to main content
Glama
README.md
# Windows Computer Use

<p align="center">
  <strong>English</strong> |
  <a href="README.zh-CN.md">简体中文</a> |
  <a href="README.ja.md">日本語</a> |
  <a href="README.fr.md">Français</a> |
  <a href="README.de.md">Deutsch</a>
</p>

> **Lightweight, precise, context-efficient Windows desktop automation MCP engine.**  
> Pure desktop control with zero overhead by default — and when you need tutorials or SOP manuals, opt into human-paced video capture, annotated screenshots, voiceover, and Word export on demand.

[![Python 3.11+](https://img.shields.io/badge/Python-3.11%2B-3776AB?logo=python&logoColor=white)](pyproject.toml)
[![Platform Windows](https://img.shields.io/badge/Platform-Windows%2010%2F11-0078D6?logo=windows&logoColor=white)](src/win_cu)
[![MCP Ready](https://img.shields.io/badge/Protocol-MCP-10B981)](src/win_cu/mcp_server.py)
[![Tests](https://img.shields.io/badge/Unit%20Tests-23%20Passed-22C55E)](tests/test_core.py)
[![Release](https://img.shields.io/badge/Release-v0.5.0-6366F1)](https://github.com/gongzhang9396-ui/windows-computer-use/releases/tag/v0.5.0)
[![License MIT](https://img.shields.io/badge/License-MIT-F59E0B)](LICENSE)

---

## 15s Live Showcase (Everyday UIA Apps + Zero-UIA Unreal Engine 5.5)

100% live autonomous execution recorded with real-time `cua` commands — **native 46-box UIA Set-of-Marks → 1-turn REPL cross-app control → 1.4 ms OS modal guard → zero-UIA Unreal Engine 5.5 live 3D Transform, Blueprint compile, pure-Pillow icon Play & relative-mouse PIE**:

![15s Full Showcase Demo](https://github.com/gongzhang9396-ui/windows-computer-use/releases/download/v0.5.0/03_ultimate_fusion.webp)

| 1. Native 46-Box UIA Set-of-Marks & Modal Guard | 2. Zero-UIA Unreal Engine 5.5 Live 3D Scene |
| :---: | :---: |
| ![Native 46-box UIA Set-of-Marks](docs/assets/00_uia_som_46boxes.jpg) | ![UE 5.5 3D Transport Ship Scene](docs/assets/01_ue5_cf_transport_ship.jpg) |
| **3. Pure-GUI Blueprint Node Wiring & Compile** | **4. Pure-Pillow Icon Play + Win32 Relative Mouse PIE** |
| ![UE 5.5 Blueprint Node Wiring](docs/assets/02_ue5_blueprint_wired.jpg) | ![UE 5.5 PIE Gameplay](docs/assets/03_ue5_pie_battle.jpg) |

> Focused demos on [Release v0.5.0](https://github.com/gongzhang9396-ui/windows-computer-use/releases/tag/v0.5.0) (narrated CN/EN MP4s + WebPs) · Runnable examples 👉 [`examples/ue5-and-everyday-apps/`](examples/ue5-and-everyday-apps/)

---

## Why This Engine? Key Engineering Advantages

Typical computer-use agents send a full-resolution screenshot to an LLM on every click and guess raw pixel coordinates. On heavyweight Windows desktop apps (**Unreal Engine 5, Blender, CAD, Office, video editors**), that blows out context within 10 steps, drifts under 125%/150% DPI scaling, garbles CJK text, and crawls.

**`windows-computer-use` solves these pain points at the Windows OS layer:**

1. **Hybrid Semantic + Visual Grounding (No Blind Pixel Guessing)**
   - **Per-Monitor DPI Aware V2 + DWM Extended Frame Bounds + Tooltip-Safe Coordinate Spaces (`v0.4.0`)**: eliminates 125%/150% scaling drift, Windows 7px shadow offsets, and hover-tooltip popup drift; supports explicit stateless `space="window"|"desktop"|"px"` plus `click_px`/`drag_px` helpers and dual `screen_center` / `window_norm_center` on every `TextMatch`.
   - **Cache-Backed & Adaptive UI Automation (`UIAutomationCore.dll`)**: prunes noisy WPF/Electron subtrees, captures same-PID popups/context menus, and **adaptively skips zero-UIA custom GPU windows** after 2 probes (saving 100–300 ms/step on engines like UE/Blender/Unity without hardcoding app names) while preserving native file dialogs.
   - **Native WinRT OCR + Dark-UI Tiled Upscale Fallback (`v0.4.0`) + Zero-OpenCV Icon Matching (`v0.5.0`)**: `desktop_find_text`, `desktop_click_text`, and `desktop_wait_text` run locally with **zero vision token cost** (with 2.5×–3.0× high-contrast / 2×2 tiled retry on miss); for textless toolbar icons (▶/■/`+`), `cua.find_icon` / `cua.click_icon` / `cua.crop_template` run ZNCC template matching with auto `cv2 → numpy → pure Pillow` fallback (~28 ms on 400×100 ROI with zero extra dependencies).
2. **DeepSeek-Style Persistent Code Execution (`desktop_run_code`) + `v0.5.0` Reliability & Speed Primitives**
   - Injects a persistent `cua` Python runtime supporting loops, conditionals, state waits, and multi-app switching — **compressing 20 LLM round-trips into 1 call** while projecting only selected text or ROI crops back via `inspect()`.
   - **Strict Focus, Safe Close & Zero-OCR Modal Guard (`v0.5.0`)**: `cua.focus(..., strict=True)` verifies real `GetForegroundWindow() == hwnd` (auto-retries via `AttachThreadInput`, reports `covered_by_title`), `cua.close_window()` sends safe `WM_CLOSE` with `IsWindow` polling, and `cua.handle_modal()` probes dialogs via pure Win32 in **~1.4 ms (0 OCR / 0 screenshots when no modal exists)**.
   - **~20 ms Fast Capture, Local Region Waits & Relative Mouse (`v0.5.0`)**: `cua.observe(include_uia=False, include_ocr="never")` captures 1920×1040 in **~20.6 ms** (~30.1 ms with `.jpg` export); `cua.wait_region_change()` / `cua.wait_region_settle()` replace blind `sleep()` without taskbar interference; `cua.mouse_move_rel(dx, dy)` unlocks mouse-locked 3D viewports, CAD orbit, games, and RDP via pure Win32 `MOUSEEVENTF_MOVE`.
   - Automatically releases all held mouse buttons and modifier keys in reverse order on error, plus a hardware kill-switch (top-left corner / `Pause` / `Ctrl+Alt+Shift+Q`) for instant human takeover.
3. **Rock-Solid CJK & Unicode Input**: `SendInput(KEYEVENTF_UNICODE)` plus lossless clipboard-snapshot paste handles long file paths and Chinese/Japanese/accented parameters cleanly.
4. **Strict Separation: Pure Control by Default, Recording Strictly Opt-In**
   - Normal calls (`desktop_click`, `desktop_type`, `desktop_run_code`) run at full speed with **zero video recording, zero TTS, and zero slowdown**.
   - Only when you explicitly start `desktop_demo(action="start", ...)` does it enable cubic-Bezier human cursor motion, StackShot red-box numbered PNGs, ffmpeg `1920×1040@30fps` capture, Word SOP manuals (`manual.docx`), crisp single-line ≤24-char ASS/SRT subtitles, and optional TTS/vocal EQ — with every output controlled by an independent boolean switch (`record_video`, `tts_voice`, `build_docx`, `mux_audio`, `burn_subtitles`).

---

## Real-World Speed Benchmarks

Measured live on Windows 10/11 (`1920×1040`) across both native UIA apps (Calculator, Notepad, VS Code, Chrome) and zero-UIA GPU engines (**Unreal Engine 5.5**, **Blender**):

| Stage / Operation | Pure-GUI Time | Notes |
|---|---:|---|
| Fast `observe()` (`include_uia=False, include_ocr="never"`) | **~20.6 ms** (mem) / **~30.1 ms** (`.jpg`) | Persistent thread-local `mss` + lazy encode (`1920×1040`) |
| Zero-OCR modal guard `handle_modal()` (idle / active) | **~1.4 ms** (no modal) / **~285 ms** (dismiss) | Pure Win32 modal probe (`0 OCR` / `0 screenshots` when idle) |
| Pure-Pillow icon match (`400×100` ROI, `28×28` icon) | **~28.0 ms** | Zero OpenCV/NumPy dependency; `compute_frame_mad` **~0.32 ms** |
| Single UIA Set-of-Marks lookup / WinRT OCR localization | **~50 – 350 ms** | Local ROI crop, zero full-screen image tokens |
| Cross-app everyday flow (Calc + Notepad + OS Save modal) | **~11 s** (1 REPL call) | 46 UIA boxes, strict focus switch, lossless CJK Unicode, auto modal guard |
| Zero-UIA UE 5.5 batch build (14 actors, ~100 numeric fields) | **69 s** (1 REPL phase) | Dark GPU Slate UI (`UIA = 0`), Blueprint compile + PIE playtest |

---

## MCP Tool Suite (16 Tools)

- **Windows & Perception**: `desktop_windows`, `desktop_observe` (Set-of-Marks / 1:1 ROI zoom / 0..1000 grid / frame-diff dedup)
- **Zero-Image Semantic Grounding**: `desktop_find_text`, `desktop_click_text`, `desktop_wait_text`
- **Precision Input & Control**: `desktop_click`, `desktop_type`, `desktop_hotkey`, `desktop_drag`, `desktop_scroll`, `desktop_batch`, `desktop_wait`, `desktop_clipboard`
- **Stateful Orchestration**: `desktop_run_code`, `desktop_reset`
- **Opt-In Demo / SOP Recorder (Off by Default)**: `desktop_demo` (`start` / `step` / `narrate` / `stop` / `status`)

---

## Quick Start

### 1. Install (Windows 10/11 + Python 3.11+)

```powershell
git clone https://github.com/gongzhang9396-ui/windows-computer-use.git
cd windows-computer-use

python -m venv .venv
.\.venv\Scripts\Activate.ps1

# Core desktop automation engine (recommended for everyday use)
pip install -e .

# Optional: Word SOP manual export (.docx)
pip install -e ".[demo]"
```

> If you plan to use optional video recording or audio muxing, make sure `ffmpeg` is on your `PATH` (e.g. `winget install Gyan.FFmpeg`).

### 2. Register as an MCP Server

See [`plugin/mcp_config.json`](plugin/mcp_config.json) to register in your MCP client (Antigravity, Claude Desktop, Cursor, etc.):

```json
{
  "mcpServers": {
    "windows-computer-use": {
      "command": "C:\\path\\to\\windows-computer-use\\.venv\\Scripts\\python.exe",
      "args": ["-m", "win_cu.mcp_server"],
      "env": {
        "PYTHONIOENCODING": "utf-8",
        "PYTHONUTF8": "1"
      }
    }
  }
}
```

### 3. (Optional) Local TTS Credentials (Never Committed)

Only needed if you opt into TTS narration / voice cloning inside `desktop_demo`:

- Option A: set the `MIMO_API_KEY` environment variable
- Option B: create `%USERPROFILE%\.win_cu_secrets.json`:
  ```json
  {
    "mimo_api_key": "YOUR_API_KEY_HERE",
    "default_voice_ref": "C:\\path\\to\\your_reference_voice.wav"
  }
  ```

### 4. Run Unit Tests

```powershell
python -m unittest discover -s tests -v
```

---

## Repository Structure

```text
windows-computer-use/
├── src/win_cu/               # Core engine (Win32 DPI / UIA / WinRT OCR / persistent REPL / opt-in demo recorder)
├── plugin/                   # Antigravity / MCP plugin manifest, rules, and skill definition
├── tests/                    # 23 core unit tests
├── benchmarks/               # Clean UIA Set-of-Marks OCR benchmark image
├── docs/assets/              # Live showcase screenshots (UIA SoM + Unreal Engine 5.5 + Blender)
├── examples/
│   └── ue5-and-everyday-apps/# Runnable pure-GUI everyday-app & zero-UIA UE 5.5 examples
└── pyproject.toml
```

---

## Security & Scope

- **No Privilege Escalation**: elevated/UAC windows surface `ADMIN_UIPI_BLOCKED` cleanly — Windows UIPI boundaries are never bypassed.
- **Zero Secrets in Git**: contains no API keys, private credentials, personal voice recordings, or internal hostnames.
- **Best-Fit Scope**: excels at desktop forms, menus, tool chains, cross-app workflows, 3D editors, and snap-assisted controls; not intended for freehand pixel-level illustration.

---

## Acknowledgements & References

Special thanks to the **[LINUX DO](https://linux.do)** community for inspiring discussions and open-source AI/Computer Use sharing, as well as the following projects and ecosystems that inspired parts of this engine:

- **[deepseek-ai/deepseek-harness (`cua-mcp`)](https://github.com/deepseek-ai/deepseek-harness)** — Core inspiration for `desktop_run_code` (persistent Python REPL orchestration, selective `inspect()` context projection, and reverse-order held-input auto-release).
- **[orakulzero/agy-computer-use](https://github.com/orakulzero/agy-computer-use)** & **[CursorTouch/Windows-MCP](https://github.com/CursorTouch/Windows-MCP)** — Inspiration for native Windows UIA + Set-of-Marks grounding and lightweight MCP server integration.
- **[microsoft/UFO](https://github.com/microsoft/UFO)** & **[microsoft/OmniParser](https://github.com/microsoft/OmniParser)** — Inspiration for Windows GUI agent architecture, UIA pruning, and visual grounding on non-UIA canvases.
- **[rubenitx/stackshot](https://github.com/rubenitx/stackshot)** — Visual inspiration for the opt-in tutorial recorder's red-box numbered callout screenshots.
- **Core Open-Source Ecosystem**: [Model Context Protocol (`mcp`)](https://github.com/modelcontextprotocol/python-sdk), [`mss`](https://github.com/BoboTiG/python-mss), [Pillow](https://github.com/python-pillow/Pillow), [`comtypes`](https://github.com/enthought/comtypes), [`pywinrt`](https://github.com/pywinrt/pywinrt), [`python-docx`](https://github.com/python-openxml/python-docx), and [FFmpeg](https://ffmpeg.org/).