| name | Desktop Control |
| description | Control mouse, keyboard, and screen for desktop automation tasks |
Desktop Control Skill
This skill provides comprehensive desktop automation capabilities through PyAutoGUI, allowing AI agents to control the mouse, keyboard, take screenshots, and interact with the desktop environment.
How to Use This Skill
Run setup environment script by executing ./setup.sh in this skill folder to install dependencies.
As an AI agent, first you should move to this skill folder, then you can invoke desktop automation commands using the uv run desktop-agent CLI.
Command Structure
All commands follow this pattern:
uv run desktop-agent <category> <command> [arguments] [options]
Categories:
mouse - Mouse control
keyboard - Keyboard input
screen - Screenshots and screen analysis
message - User dialogs
app - Application control (open, focus, list windows)
Available Commands
🖱️ Mouse Control (mouse)
Control cursor movement and clicks.
uv run desktop-agent mouse move <x> <y> [--duration SECONDS]
uv run desktop-agent mouse click [x] [y] [--button left|right|middle] [--clicks N]
uv run desktop-agent mouse double-click [x] [y]
uv run desktop-agent mouse right-click [x] [y]
uv run desktop-agent mouse middle-click [x] [y]
uv run desktop-agent mouse drag <x> <y> [--duration SECONDS] [--button BUTTON]
uv run desktop-agent mouse scroll <clicks> [x] [y]
uv run desktop-agent mouse position
Examples:
uv run desktop-agent mouse move 960 540 --duration 0.5
uv run desktop-agent mouse right-click 500 300
uv run desktop-agent mouse scroll -5
⌨️ Keyboard Control (keyboard)
Type text and execute keyboard shortcuts.
uv run desktop-agent keyboard write "<text>" [--interval SECONDS]
uv run desktop-agent keyboard press <key> [--presses N] [--interval SECONDS]
uv run desktop-agent keyboard hotkey "<key1>,<key2>,..."
uv run desktop-agent keyboard keydown <key>
uv run desktop-agent keyboard keyup <key>
Examples:
uv run desktop-agent keyboard write "Hello World" --interval 0.05
uv run desktop-agent keyboard hotkey "ctrl,c"
uv run desktop-agent keyboard hotkey "ctrl,shift,esc"
uv run desktop-agent keyboard press enter --presses 3
Common Key Names:
- Modifiers:
ctrl, shift, alt, win
- Special:
enter, tab, esc, space, backspace, delete
- Function:
f1 through f12
- Arrows:
up, down, left, right
🖼️ Screen & Screenshots (screen)
Capture screenshots and analyze screen content. Supports targeting specific windows.
uv run desktop-agent screen screenshot <filename> [--region "x,y,width,height"]
uv run desktop-agent screen screenshot <filename> [--region "x,y,width,height"] [--window <title>] [--active]
uv run desktop-agent screen locate <image_path> [--confidence 0.0-1.0] [--window <title>] [--active]
uv run desktop-agent screen locate-center <image_path> [--confidence 0.0-1.0] [--window <title>] [--active]
uv run --with easyocr desktop-agent screen locate-text-coordinates <text> --lang en [--window <title>]
uv run --with easyocr desktop-agent screen read-all-text --lang en [--window <title>]
uv run desktop-agent screen pixel <x> <y>
uv run desktop-agent screen size
uv run desktop-agent screen on-screen <x> <y>
Examples:
uv run desktop-agent screen screenshot fullscreen.png
uv run desktop-agent screen screenshot chrome.png --window "Google Chrome"
uv run desktop-agent screen screenshot active.png --active
uv run desktop-agent screen locate-center button.png
💬 Message Dialogs (message)
Display user interaction dialogs.
uv run desktop-agent message alert "<text>" [--title TITLE] [--button BUTTON]
uv run desktop-agent message confirm "<text>" [--title TITLE] [--buttons "OK,Cancel"]
uv run desktop-agent message prompt "<text>" [--title TITLE] [--default TEXT]
uv run desktop-agent message password "<text>" [--title TITLE] [--mask CHAR]
Examples:
uv run desktop-agent message alert "Task completed!"
uv run desktop-agent message confirm "Continue with operation?"
uv run desktop-agent message prompt "Enter your name:"
📱 Application Control (app)
Control applications across Windows, macOS, and Linux.
uv run desktop-agent app open <name> [--arg ARGS...]
uv run desktop-agent app focus <name>
uv run desktop-agent app list
Examples:
uv run desktop-agent app open notepad
uv run desktop-agent app open "chrome" --arg "https://google.com"
uv run desktop-agent app open "Safari"
uv run desktop-agent app focus "Untitled - Notepad"
uv run desktop-agent app list
Common Automation Workflows
Workflow 1: Open Application and Type
uv run desktop-agent app open notepad
uv run desktop-agent app focus notepad
uv run desktop-agent keyboard write "Hello from Desktop Skill!"
Workflow 2: Screenshot + Analysis
uv run desktop-agent screen size
uv run desktop-agent screen screenshot current_screen.png
uv run desktop-agent screen locate save_button.png
Workflow 3: Form Filling
uv run desktop-agent mouse click 300 200
uv run desktop-agent keyboard write "John Doe"
uv run desktop-agent keyboard press tab
uv run desktop-agent keyboard write "john@example.com"
uv run desktop-agent keyboard press enter
Workflow 4: Copy/Paste Operations
uv run desktop-agent keyboard hotkey "ctrl,a"
uv run desktop-agent keyboard hotkey "ctrl,c"
uv run desktop-agent mouse click 500 600
uv run desktop-agent keyboard hotkey "ctrl,v"
Safety Considerations
When using this skill, AI agents should:
- Verify coordinates: Use
screen size and on-screen before clicking
- Add delays: Insert appropriate delays between commands for UI responsiveness
- Validate images: Ensure image files exist before using
locate commands
- Handle failures: Commands may fail if windows change or elements move
- User safety: Always confirm destructive actions with user via
message confirm
Troubleshooting
PyAutoGUI Fail-Safe
PyAutoGUI has a fail-safe: moving mouse to screen corner aborts operations. This is a safety feature.
Image not found
When using screen locate, ensure:
- Image file exists and path is correct
- Adjust
--confidence (try 0.7-0.9)
- Image matches exact screen appearance (resolution, colors)
Getting Help
uv run desktop-agent --help
uv run desktop-agent mouse --help
uv run desktop-agent keyboard --help
uv run desktop-agent screen --help
uv run desktop-agent message --help
uv run desktop-agent mouse move --help
Integration Tips for AI Agents
- Always check screen size first when working with absolute coordinates
- Use relative positioning when possible (e.g., get current position, calculate offset)
- Combine commands for complex workflows
- Validate before executing (e.g., check if image exists on screen)
- Provide user feedback using message dialogs for important operations
- Handle errors gracefully - commands may fail if UI state changes
Performance Notes
- Mouse movements with
--duration are animated and take time
- Image location (
locate) can be slow on large screens - use regions when possible
- Keyboard commands are generally fast (< 100ms)
- Screenshots depend on screen resolution and region size
Output Format
All commands output structured JSON by default, ideal for programmatic use by AI agents:
uv run desktop-agent mouse position
Response Schema
All JSON responses follow this schema:
{
"success": true,
"command": "category.command",
"timestamp": "2026-01-31T10:00:00Z",
"duration_ms": 150,
"data": { ... },
"error": null
}
Error Response Schema
{
"success": false,
"command": "category.command",
"timestamp": "2026-01-31T10:00:00Z",
"duration_ms": 50,
"data": null,
"error": {
"code": "image_not_found",
"message": "Image file 'button.png' not found",
"details": {},
"recoverable": true
}
}
Error Codes
| Code | Description |
|---|
success | Command succeeded |
invalid_argument | Invalid command arguments |
coordinates_out_of_bounds | Coordinates outside screen |
image_not_found | Image file not found or not on screen |
window_not_found | Target window not found |
ocr_failed | OCR operation failed |
application_not_found | Application not found |
permission_denied | Permission denied |
platform_not_supported | Platform not supported |
timeout | Operation timed out |
unknown_error | Unknown error |
Mouse move:
uv run desktop-agent mouse move 960 540
{"success": true, "command": "mouse.move", "timestamp": "...", "duration_ms": 150, "data": {"x": 960, "y": 540, "duration": 0}, "error": null}
Screen size:
uv run desktop-agent screen size
{"success": true, "command": "screen.size", "timestamp": "...", "duration_ms": 5, "data": {"size": {"width": 1920, "height": 1080}}, "error": null}
Locate image:
uv run desktop-agent screen locate button.png
{"success": true, "command": "screen.locate", "timestamp": "...", "duration_ms": 250, "data": {"image_found": true, "bounding_box": {"left": 100, "top": 200, "width": 50, "height": 30, "center_x": 125, "center_y": 215}}, "error": null}
List windows:
uv run desktop-agent app list
{"success": true, "command": "app.list", "timestamp": "...", "duration_ms": 100, "data": {"windows": ["Untitled - Notepad", "Google Chrome", "Visual Studio Code"]}, "error": null}
Error example:
uv run desktop-agent screen locate missing.png
{"success": false, "command": "screen.locate", "timestamp": "...", "duration_ms": 50, "data": null, "error": {"code": "image_not_found", "message": "Image file 'missing.png' not found", "details": {}, "recoverable": true}}
Effective Usage Guide for AI Agents
This section teaches AI agents how to use this skill effectively with optimal command sequences and best practices.
🎯 Core Strategy: Observe First, Then Act
Always understand the current state before performing actions. This avoids clicking wrong coordinates or typing in the wrong window.
Recommended Initial Sequence:
uv run desktop-agent screen size
uv run desktop-agent app list
uv run desktop-agent mouse position
📋 Recommended Command Sequences by Task
Open and Interact with Application
uv run desktop-agent app open notepad
uv run desktop-agent app list
uv run desktop-agent app focus "Notepad"
uv run desktop-agent keyboard write "Hello World"
uv run desktop-agent app open notepad
uv run desktop-agent keyboard write "Hello World"
Find and Click UI Element (Image-Based)
uv run desktop-agent screen locate-center button.png --confidence 0.8
uv run desktop-agent mouse click 125 215
uv run desktop-agent mouse click 125 215
Find and Click UI Element (Text-Based with OCR)
uv run --with easyocr desktop-agent screen read-all-text --lang en
uv run --with easyocr desktop-agent screen locate-text-coordinates "Save" --lang en
uv run --with easyocr desktop-agent screen locate-text-coordinates "OK" --lang en --window "Dialog Title"
Fill a Form with Multiple Fields
uv run desktop-agent mouse click 300 200
uv run desktop-agent keyboard write "John Doe"
uv run desktop-agent mouse click 300 250
uv run desktop-agent keyboard write "john@example.com"
uv run desktop-agent mouse click 300 300
uv run desktop-agent keyboard write "555-1234"
uv run desktop-agent mouse click 300 200
uv run desktop-agent keyboard write "John Doe"
uv run desktop-agent keyboard press tab
uv run desktop-agent keyboard write "john@example.com"
uv run desktop-agent keyboard press tab
uv run desktop-agent keyboard write "555-1234"
uv run desktop-agent keyboard press enter
Take Targeted Screenshots for Analysis
uv run desktop-agent app list --json
uv run desktop-agent screen screenshot app.png --window "Google Chrome"
uv run desktop-agent screen size
uv run desktop-agent screen screenshot fullscreen.png
uv run desktop-agent screen screenshot active.png --active
Safe Drag and Drop
uv run desktop-agent mouse move 100 200
uv run desktop-agent mouse position
uv run desktop-agent mouse drag 500 400 --duration 0.5
uv run desktop-agent mouse drag 500 400 --duration 1.0
🔄 Error Recovery Patterns
When Window Not Found
uv run desktop-agent app focus "Chrome"
uv run desktop-agent app list
uv run desktop-agent app focus "Google Chrome"
When Image Not Found
uv run desktop-agent screen locate button.png --confidence 0.9
uv run desktop-agent screen locate button.png --confidence 0.7
uv run desktop-agent screen screenshot current.png
When Click Seems to Miss
uv run desktop-agent screen size
uv run desktop-agent screen on-screen 1500 900
uv run desktop-agent mouse move 1500 900
uv run desktop-agent mouse click
⚡ Performance Optimization
Minimize Screenshots
uv run desktop-agent screen screenshot button_area.png --region "100,200,200,100"
uv run desktop-agent screen screenshot chrome.png --window "Google Chrome"
uv run desktop-agent screen screenshot full.png
Batch Keyboard Input
uv run desktop-agent keyboard write "This is a complete sentence with all the text."
uv run desktop-agent keyboard write "This is "
uv run desktop-agent keyboard write "a complete "
uv run desktop-agent keyboard write "sentence."
Use Hotkeys Over Mouse When Possible
uv run desktop-agent keyboard hotkey "ctrl,s"
uv run desktop-agent keyboard hotkey "ctrl,a"
uv run desktop-agent keyboard hotkey "ctrl,shift,s"
uv run desktop-agent mouse click 50 30
uv run desktop-agent mouse click 60 80
🛡️ Defensive Programming Patterns
Always Verify Critical Actions
uv run desktop-agent message confirm "This will delete all files. Continue?" --title "Warning"
Use JSON Mode for Reliable Parsing
uv run desktop-agent screen locate button.png
uv run desktop-agent screen locate button.png
Validate Before Multi-Step Operations
uv run desktop-agent app list
uv run --with easyocr desktop-agent screen locate-text-coordinates "File" --lang en
uv run desktop-agent mouse click <returned_x> <returned_y>
uv run --with easyocr desktop-agent screen locate-text-coordinates "Save As" --lang en
uv run desktop-agent mouse click <returned_x> <returned_y>
🎮 Platform-Specific Considerations
Windows
uv run desktop-agent keyboard hotkey "win,d"
uv run desktop-agent keyboard hotkey "win,e"
uv run desktop-agent keyboard hotkey "alt,tab"
uv run desktop-agent keyboard hotkey "win,r"
uv run desktop-agent app open notepad
uv run desktop-agent app open calc
uv run desktop-agent app open mspaint
macOS
uv run desktop-agent keyboard hotkey "command,space"
uv run desktop-agent keyboard hotkey "command,tab"
uv run desktop-agent keyboard hotkey "command,q"
uv run desktop-agent keyboard hotkey "command,shift,3"
uv run desktop-agent app open "Safari"
uv run desktop-agent app open "TextEdit"
Linux
uv run desktop-agent app open firefox
uv run desktop-agent app open gedit
uv run desktop-agent keyboard hotkey "alt,f2"
📊 Decision Tree: Choosing the Right Command
Want to interact with an app?
├── App not running → `app open <name>`
├── App running but not focused → `app focus <name>`
└── Need to verify windows → `app list`
Want to find a UI element?
├── Have reference image → `screen locate-center <image>`
├── Know the text label → `screen locate-text-coordinates "<text>" --lang en` (requires --with easyocr)
└── Need to see all text → `screen read-all-text --lang en` (requires --with easyocr)
Want to click something?
├── Know exact coordinates → `mouse click <x> <y>`
├── Need to find first → Use locate commands above, then click returned coords
└── Not sure if on screen → `screen on-screen <x> <y>` first
Want to type something?
├── Regular text → `keyboard write "<text>"`
├── Keyboard shortcut → `keyboard hotkey "<key1>,<key2>"`
├── Single key press → `keyboard press <key>`
└── Multiple of same key → `keyboard press <key> --presses N`
Integration Tips for AI Agents
- Always check screen size first when working with absolute coordinates
- Use relative positioning when possible (e.g., get current position, calculate offset)
- Combine commands for complex workflows
- Validate before executing (e.g., check if image exists on screen)
- Provide user feedback using message dialogs for important operations
- Handle errors gracefully - commands may fail if UI state changes