Skills/ #automation

Desktop Control

Advanced desktop automation with mouse, keyboard, and screen control

matagul@matagul

Install

Run this command against the local KakaHub registry.

Install desktop-control from the local KakaHub registry at http://localhost:13001. Review the README, manifest, and permissions before using it in the current workspace.Download

README

--- description: Advanced desktop automation with mouse, keyboard, and screen control ---

Desktop Control Skill

**The most advanced desktop automation skill for OpenClaw.** Provides pixel-perfect mouse control, lightning-fast keyboard input, screen capture, window management, and clipboard operations.

🎯 Features

Mouse Control

  • βœ… **Absolute positioning** - Move to exact coordinates
  • βœ… **Relative movement** - Move from current position
  • βœ… **Smooth movement** - Natural, human-like mouse paths
  • βœ… **Click types** - Left, right, middle, double, triple clicks
  • βœ… **Drag & drop** - Drag from point A to point B
  • βœ… **Scroll** - Vertical and horizontal scrolling
  • βœ… **Position tracking** - Get current mouse coordinates

Keyboard Control

  • βœ… **Text typing** - Fast, accurate text input
  • βœ… **Hotkeys** - Execute keyboard shortcuts (Ctrl+C, Win+R, etc.)
  • βœ… **Special keys** - Enter, Tab, Escape, Arrow keys, F-keys
  • βœ… **Key combinations** - Multi-key press combinations
  • βœ… **Hold & release** - Manual key state control
  • βœ… **Typing speed** - Configurable WPM (instant to human-like)

Screen Operations

  • βœ… **Screenshot** - Capture entire screen or regions
  • βœ… **Image recognition** - Find elements on screen (via OpenCV)
  • βœ… **Color detection** - Get pixel colors at coordinates
  • βœ… **Multi-monitor** - Support for multiple displays

Window Management

  • βœ… **Window list** - Get all open windows
  • βœ… **Activate window** - Bring window to front
  • βœ… **Window info** - Get position, size, title
  • βœ… **Minimize/Maximize** - Control window states

Safety Features

  • βœ… **Failsafe** - Move mouse to corner to abort
  • βœ… **Pause control** - Emergency stop mechanism
  • βœ… **Approval mode** - Require confirmation for actions
  • βœ… **Bounds checking** - Prevent out-of-screen operations
  • βœ… **Logging** - Track all automation actions

---

πŸš€ Quick Start

Installation

First, install required dependencies:

bashpip install pyautogui pillow opencv-python pygetwindow

Basic Usage

pythonfrom skills.desktop_control import DesktopController

# Initialize controller
dc = DesktopController(failsafe=True)

# Mouse operations
dc.move_mouse(500, 300)  # Move to coordinates
dc.click()  # Left click at current position
dc.click(100, 200, button="right")  # Right click at position

# Keyboard operations
dc.type_text("Hello from OpenClaw!")
dc.hotkey("ctrl", "c")  # Copy
dc.press("enter")

# Screen operations
screenshot = dc.screenshot()
position = dc.get_mouse_position()

---

πŸ“‹ Complete API Reference

Mouse Functions

#### `move_mouse(x, y, duration=0, smooth=True)` Move mouse to absolute screen coordinates.

**Parameters:**

  • `x` (int): X coordinate (pixels from left)
  • `y` (int): Y coordinate (pixels from top)
  • `duration` (float): Movement time in seconds (0 = instant, 0.5 = smooth)
  • `smooth` (bool): Use bezier curve for natural movement

**Example:**

python# Instant movement
dc.move_mouse(1000, 500)

# Smooth 1-second movement
dc.move_mouse(1000, 500, duration=1.0)

#### `move_relative(x_offset, y_offset, duration=0)` Move mouse relative to current position.

**Parameters:**

  • `x_offset` (int): Pixels to move horizontally (positive = right)
  • `y_offset` (int): Pixels to move vertically (positive = down)
  • `duration` (float): Movement time in seconds

**Example:**

python# Move 100px right, 50px down
dc.move_relative(100, 50, duration=0.3)

#### `click(x=None, y=None, button='left', clicks=1, interval=0.1)` Perform mouse click.

**Parameters:**

  • `x, y` (int, optional): Coordinates to click (None = current position)
  • `button` (str): 'left', 'right', 'middle'
  • `clicks` (int): Number of clicks (1 = single, 2 = double)
  • `interval` (float): Delay between multiple clicks

**Example:**

python# Simple left click
dc.click()

# Double-click at specific position
dc.click(500, 300, clicks=2)

# Right-click
dc.click(button='right')

#### `drag(start_x, start_y, end_x, end_y, duration=0.5, button='left')` Drag and drop operation.

**Parameters:**

  • `start_x, start_y` (int): Starting coordinates
  • `end_x, end_y` (int): Ending coordinates
  • `duration` (float): Drag duration
  • `button` (str): Mouse button to use

**Example:**

python# Drag file from desktop to folder
dc.drag(100, 100, 500, 500, duration=1.0)

#### `scroll(clicks, direction='vertical', x=None, y=None)` Scroll mouse wheel.

**Parameters:**

  • `clicks` (int): Scroll amount (positive = up/left, negative = down/right)
  • `direction` (str): 'vertical' or 'horizontal'
  • `x, y` (int, optional): Position to scroll at

**Example:**

python# Scroll down 5 clicks
dc.scroll(-5)

# Scroll up 10 clicks
dc.scroll(10)

# Horizontal scroll
dc.scroll(5, direction='horizontal')

#### `get_mouse_position()` Get current mouse coordinates.

**Returns:** `(x, y)` tuple

**Example:**

pythonx, y = dc.get_mouse_position()
print(f"Mouse is at: {x}, {y}")

---

Keyboard Functions

#### `type_text(text, interval=0, wpm=None)` Type text with configurable speed.

**Parameters:**

  • `text` (str): Text to type
  • `interval` (float): Delay between keystrokes (0 = instant)
  • `wpm` (int, optional): Words per minute (overrides interval)

**Example:**

python# Instant typing
dc.type_text("Hello World")

# Human-like typing at 60 WPM
dc.type_text("Hello World", wpm=60)

# Slow typing with 0.1s between keys
dc.type_text("Hello World", interval=0.1)

#### `press(key, presses=1, interval=0.1)` Press and release a key.

**Parameters:**

  • `key` (str): Key name (see Key Names section)
  • `presses` (int): Number of times to press
  • `interval` (float): Delay between presses

**Example:**

python# Press Enter
dc.press('enter')

# Press Space 3 times
dc.press('space', presses=3)

# Press Down arrow
dc.press('down')

#### `hotkey(*keys, interval=0.05)` Execute keyboard shortcut.

**Parameters:**

  • `*keys` (str): Keys to press together
  • `interval` (float): Delay between key presses

**Example:**

python# Copy (Ctrl+C)
dc.hotkey('ctrl', 'c')

# Paste (Ctrl+V)
dc.hotkey('ctrl', 'v')

# Open Run dialog (Win+R)
dc.hotkey('win', 'r')

# Save (Ctrl+S)
dc.hotkey('ctrl', 's')

# Select All (Ctrl+A)
dc.hotkey('ctrl', 'a')

#### `key_down(key)` / `key_up(key)` Manually control key state.

**Example:**

python# Hold Shift
dc.key_down('shift')
dc.type_text("hello")  # Types "HELLO"
dc.key_up('shift')

# Hold Ctrl and click (for multi-select)
dc.key_down('ctrl')
dc.click(100, 100)
dc.click(200, 100)
dc.key_up('ctrl')

---

Screen Functions

#### `screenshot(region=None, filename=None)` Capture screen or region.

**Parameters:**

  • `region` (tuple, optional): (left, top, width, height) for partial capture
  • `filename` (str, optional): Path to save image

**Returns:** PIL Image object

**Example:**

python# Full screen
img = dc.screenshot()

# Save to file
dc.screenshot(filename="screenshot.png")

# Capture specific region
img = dc.screenshot(region=(100, 100, 500, 300))

#### `get_pixel_color(x, y)` Get color of pixel at coordinates.

**Returns:** RGB tuple `(r, g, b)`

**Example:**

pythonr, g, b = dc.get_pixel_color(500, 300)
print(f"Color at (500, 300): RGB({r}, {g}, {b})")

#### `find_on_screen(image_path, confidence=0.8)` Find image on screen (requires OpenCV).

**Parameters:**

  • `image_path` (str): Path to template image
  • `confidence` (float): Match threshold (0-1)

**Returns:** `(x, y, width, height)` or None

**Example:**

python# Find button on screen
location = dc.find_on_screen("button.png")
if location:
    x, y, w, h = location
    # Click center of found image
    dc.click(x + w//2, y + h//2)

#### `get_screen_size()` Get screen resolution.

**Returns:** `(width, height)` tuple

**Example:**

pythonwidth, height = dc.get_screen_size()
print(f"Screen: {width}x{height}")

---

Window Functions

#### `get_all_windows()` List all open windows.

**Returns:** List of window titles

**Example:**

pythonwindows = dc.get_all_windows()
for title in windows:
    print(f"Window: {title}")

#### `activate_window(title_substring)` Bring window to front by title.

**Parameters:**

  • `title_substring` (str): Part of window title to match

**Example:**

python# Activate Chrome
dc.activate_window("Chrome")

# Activate VS Code
dc.activate_window("Visual Studio Code")

#### `get_active_window()` Get currently focused window.

**Returns:** Window title (str)

**Example:**

pythonactive = dc.get_active_window()
print(f"Active window: {active}")

---

Clipboard Functions

#### `copy_to_clipboard(text)` Copy text to clipboard.

**Example:**

pythondc.copy_to_clipboard("Hello from OpenClaw!")

#### `get_from_clipboard()` Get text from clipboard.

**Returns:** str

**Example:**

pythontext = dc.get_from_clipboard()
print(f"Clipboard: {text}")

---

⌨️ Key Names Reference

Alphabet Keys

`'a'` through `'z'`

Number Keys

`'0'` through `'9'`

Function Keys

`'f1'` through `'f24'`

Special Keys

  • `'enter'` / `'return'`
  • `'esc'` / `'escape'`
  • `'space'` / `'spacebar'`
  • `'tab'`
  • `'backspace'`
  • `'delete'` / `'del'`
  • `'insert'`
  • `'home'`
  • `'end'`
  • `'pageup'` / `'pgup'`
  • `'pagedown'` / `'pgdn'`

Arrow Keys

  • `'up'` / `'down'` / `'left'` / `'right'`

Modifier Keys

  • `'ctrl'` / `'control'`
  • `'shift'`
  • `'alt'`
  • `'win'` / `'winleft'` / `'winright'`
  • `'cmd'` / `'command'` (Mac)

Lock Keys

  • `'capslock'`
  • `'numlock'`
  • `'scrolllock'`

Punctuation

  • `'.'` / `','` / `'?'` / `'!'` / `';'` / `':'`
  • `'['` / `']'` / `'{'` / `'}'`
  • `'('` / `')'`
  • `'+'` / `'-'` / `'*'` / `'/'` / `'='`

---

πŸ›‘οΈ Safety Features

Failsafe Mode

Move mouse to **any corner** of the screen to abort all automation.

python# Enable failsafe (enabled by default)
dc = DesktopController(failsafe=True)

Pause Control

python# Pause all automation for 2 seconds
dc.pause(2.0)

# Check if automation is safe to proceed
if dc.is_safe():
    dc.click(500, 500)

Approval Mode

Require user confirmation before actions:

pythondc = DesktopController(require_approval=True)

# This will ask for confirmation
dc.click(500, 500)  # Prompt: "Allow click at (500, 500)? [y/n]"

---

🎨 Advanced Examples

Example 1: Automated Form Filling

pythondc = DesktopController()

# Click name field
dc.click(300, 200)
dc.type_text("John Doe", wpm=80)

# Tab to next field
dc.press('tab')
dc.type_text("john@example.com", wpm=80)

# Tab to password
dc.press('tab')
dc.type_text("SecurePassword123", wpm=60)

# Submit form
dc.press('enter')

Example 2: Screenshot Region and Save

python# Capture specific area
region = (100, 100, 800, 600)  # left, top, width, height
img = dc.screenshot(region=region)

# Save with timestamp
import datetime
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
img.save(f"capture_{timestamp}.png")

Example 3: Multi-File Selection

python# Hold Ctrl and click multiple files
dc.key_down('ctrl')
dc.click(100, 200)  # First file
dc.click(100, 250)  # Second file
dc.click(100, 300)  # Third file
dc.key_up('ctrl')

# Copy selected files
dc.hotkey('ctrl', 'c')

Example 4: Window Automation

python# Activate Calculator
dc.activate_window("Calculator")
time.sleep(0.5)

# Type calculation
dc.type_text("5+3=", interval=0.2)
time.sleep(0.5)

# Take screenshot of result
dc.screenshot(filename="calculation_result.png")

Example 5: Drag & Drop File

python# Drag file from source to destination
dc.drag(
    start_x=200, start_y=300,  # File location
    end_x=800, end_y=500,       # Folder location
    duration=1.0                 # Smooth 1-second drag
)

---

⚑ Performance Tips

1. **Use instant movements** for speed: `duration=0` 2. **Batch operations** instead of individual calls 3. **Cache screen positions** instead of recalculating 4. **Disable failsafe** for maximum performance (use with caution) 5. **Use hotkeys** instead of menu navigation

---

⚠️ Important Notes

  • **Screen coordinates** start at (0, 0) in top-left corner
  • **Multi-monitor setups** may have negative coordinates for secondary displays
  • **Windows DPI scaling** may affect coordinate accuracy
  • **Failsafe corners** are: (0,0), (width-1, 0), (0, height-1), (width-1, height-1)
  • **Some applications** may block simulated input (games, secure apps)

---

πŸ”§ Troubleshooting

Mouse not moving to correct position

  • Check DPI scaling settings
  • Verify screen resolution matches expectations
  • Use `get_screen_size()` to confirm dimensions

Keyboard input not working

  • Ensure target application has focus
  • Some apps require admin privileges
  • Try increasing `interval` for reliability

Failsafe triggering accidentally

  • Increase screen border tolerance
  • Move mouse away from corners during normal use
  • Disable if needed: `DesktopController(failsafe=False)`

Permission errors

  • Run Python with administrator privileges for some operations
  • Some secure applications block automation

---

πŸ“¦ Dependencies

  • **PyAutoGUI** - Core automation engine
  • **Pillow** - Image processing
  • **OpenCV** (optional) - Image recognition
  • **PyGetWindow** - Window management

Install all:

bashpip install pyautogui pillow opencv-python pygetwindow

---

**Built for OpenClaw** - The ultimate desktop automation companion 🦞

Install resolver

{
  "artifact": {
    "downloadUrl": "/api/v1/download?slug=desktop-control&version=1.0.0&ownerHandle=matagul",
    "format": "zip",
    "generated": true,
    "kind": "skillArchive",
    "sha256": "85277edef5f72a4e92f4a405c22775780927828f041f385b04a1177d87e3f1e4",
    "size": 15198
  },
  "owner": {
    "displayName": "matagul",
    "handle": "matagul",
    "id": "aded540a-62ef-474c-a729-673cdd712890",
    "verified": false
  },
  "skill": {
    "displayName": "Desktop Control",
    "latestVersion": "1.0.0",
    "license": "unknown",
    "name": "desktop-control",
    "ownerHandle": "matagul",
    "slug": "desktop-control",
    "stats": {
      "downloads": 59964,
      "installs": 1860,
      "stars": 373
    },
    "summary": "Advanced desktop automation with mouse, keyboard, and screen control",
    "tags": [
      "automation"
    ],
    "type": "skill",
    "updatedAt": "2026-07-06T10:48:55.230Z"
  },
  "sourceHandoff": null,
  "version": {
    "checksum": null,
    "checksumAlgorithm": null,
    "id": "c6764c0b-c1d2-41b3-bffc-3792ea87b5c0",
    "publishedAt": "2026-02-05T01:33:20.863Z",
    "size": null,
    "version": "1.0.0",
    "artifactStorageKey": null,
    "changelog": "Version 1.0.0\n\n- Initial release of the Desktop Control skill for OpenClaw.\n- Provides advanced automation: mouse movement/clicks, keyboard input, hotkeys, and typing speed control.\n- Supports screen capture, region-based screenshots, image/template matching, and pixel color detection.\n- Includes window management (list, activate, move, resize, minimize/maximize).\n- Safety features: failsafe abort, logging, approval mode, bounds checks, and emergency pause.\n- Detailed documentation with examples and complete API reference.",
    "manifest": {
      "clawhub": {
        "tags": {
          "latest": "1.0.0"
        },
        "owner": "matagul",
        "stats": {
          "stars": 373,
          "comments": 4,
          "installs": 1860,
          "versions": 1,
          "downloads": 59964
        },
        "topics": [],
        "categories": [
          "automation"
        ]
      },
      "install": "openclaw skills install @matagul/desktop-control"
    },
    "readme": "---\r\ndescription: Advanced desktop automation with mouse, keyboard, and screen control\r\n---\r\n\r\n# Desktop Control Skill\r\n\r\n**The most advanced desktop automation skill for OpenClaw.** Provides pixel-perfect mouse control, lightning-fast keyboard input, screen capture, window management, and clipboard operations.\r\n\r\n## 🎯 Features\r\n\r\n### Mouse Control\r\n- βœ… **Absolute positioning** - Move to exact coordinates\r\n- βœ… **Relative movement** - Move from current position\r\n- βœ… **Smooth movement** - Natural, human-like mouse paths\r\n- βœ… **Click types** - Left, right, middle, double, triple clicks\r\n- βœ… **Drag & drop** - Drag from point A to point B\r\n- βœ… **Scroll** - Vertical and horizontal scrolling\r\n- βœ… **Position tracking** - Get current mouse coordinates\r\n\r\n### Keyboard Control\r\n- βœ… **Text typing** - Fast, accurate text input\r\n- βœ… **Hotkeys** - Execute keyboard shortcuts (Ctrl+C, Win+R, etc.)\r\n- βœ… **Special keys** - Enter, Tab, Escape, Arrow keys, F-keys\r\n- βœ… **Key combinations** - Multi-key press combinations\r\n- βœ… **Hold & release** - Manual key state control\r\n- βœ… **Typing speed** - Configurable WPM (instant to human-like)\r\n\r\n### Screen Operations\r\n- βœ… **Screenshot** - Capture entire screen or regions\r\n- βœ… **Image recognition** - Find elements on screen (via OpenCV)\r\n- βœ… **Color detection** - Get pixel colors at coordinates\r\n- βœ… **Multi-monitor** - Support for multiple displays\r\n\r\n### Window Management\r\n- βœ… **Window list** - Get all open windows\r\n- βœ… **Activate window** - Bring window to front\r\n- βœ… **Window info** - Get position, size, title\r\n- βœ… **Minimize/Maximize** - Control window states\r\n\r\n### Safety Features\r\n- βœ… **Failsafe** - Move mouse to corner to abort\r\n- βœ… **Pause control** - Emergency stop mechanism\r\n- βœ… **Approval mode** - Require confirmation for actions\r\n- βœ… **Bounds checking** - Prevent out-of-screen operations\r\n- βœ… **Logging** - Track all automation actions\r\n\r\n---\r\n\r\n## πŸš€ Quick Start\r\n\r\n### Installation\r\n\r\nFirst, install required dependencies:\r\n\r\n```bash\r\npip install pyautogui pillow opencv-python pygetwindow\r\n```\r\n\r\n### Basic Usage\r\n\r\n```python\r\nfrom skills.desktop_control import DesktopController\r\n\r\n# Initialize controller\r\ndc = DesktopController(failsafe=True)\r\n\r\n# Mouse operations\r\ndc.move_mouse(500, 300)  # Move to coordinates\r\ndc.click()  # Left click at current position\r\ndc.click(100, 200, button=\"right\")  # Right click at position\r\n\r\n# Keyboard operations\r\ndc.type_text(\"Hello from OpenClaw!\")\r\ndc.hotkey(\"ctrl\", \"c\")  # Copy\r\ndc.press(\"enter\")\r\n\r\n# Screen operations\r\nscreenshot = dc.screenshot()\r\nposition = dc.get_mouse_position()\r\n```\r\n\r\n---\r\n\r\n## πŸ“‹ Complete API Reference\r\n\r\n### Mouse Functions\r\n\r\n#### `move_mouse(x, y, duration=0, smooth=True)`\r\nMove mouse to absolute screen coordinates.\r\n\r\n**Parameters:**\r\n- `x` (int): X coordinate (pixels from left)\r\n- `y` (int): Y coordinate (pixels from top)\r\n- `duration` (float): Movement time in seconds (0 = instant, 0.5 = smooth)\r\n- `smooth` (bool): Use bezier curve for natural movement\r\n\r\n**Example:**\r\n```python\r\n# Instant movement\r\ndc.move_mouse(1000, 500)\r\n\r\n# Smooth 1-second movement\r\ndc.move_mouse(1000, 500, duration=1.0)\r\n```\r\n\r\n#### `move_relative(x_offset, y_offset, duration=0)`\r\nMove mouse relative to current position.\r\n\r\n**Parameters:**\r\n- `x_offset` (int): Pixels to move horizontally (positive = right)\r\n- `y_offset` (int): Pixels to move vertically (positive = down)\r\n- `duration` (float): Movement time in seconds\r\n\r\n**Example:**\r\n```python\r\n# Move 100px right, 50px down\r\ndc.move_relative(100, 50, duration=0.3)\r\n```\r\n\r\n#### `click(x=None, y=None, button='left', clicks=1, interval=0.1)`\r\nPerform mouse click.\r\n\r\n**Parameters:**\r\n- `x, y` (int, optional): Coordinates to click (None = current position)\r\n- `button` (str): 'left', 'right', 'middle'\r\n- `clicks` (int): Number of clicks (1 = single, 2 = double)\r\n- `interval` (float): Delay between multiple clicks\r\n\r\n**Example:**\r\n```python\r\n# Simple left click\r\ndc.click()\r\n\r\n# Double-click at specific position\r\ndc.click(500, 300, clicks=2)\r\n\r\n# Right-click\r\ndc.click(button='right')\r\n```\r\n\r\n#### `drag(start_x, start_y, end_x, end_y, duration=0.5, button='left')`\r\nDrag and drop operation.\r\n\r\n**Parameters:**\r\n- `start_x, start_y` (int): Starting coordinates\r\n- `end_x, end_y` (int): Ending coordinates\r\n- `duration` (float): Drag duration\r\n- `button` (str): Mouse button to use\r\n\r\n**Example:**\r\n```python\r\n# Drag file from desktop to folder\r\ndc.drag(100, 100, 500, 500, duration=1.0)\r\n```\r\n\r\n#### `scroll(clicks, direction='vertical', x=None, y=None)`\r\nScroll mouse wheel.\r\n\r\n**Parameters:**\r\n- `clicks` (int): Scroll amount (positive = up/left, negative = down/right)\r\n- `direction` (str): 'vertical' or 'horizontal'\r\n- `x, y` (int, optional): Position to scroll at\r\n\r\n**Example:**\r\n```python\r\n# Scroll down 5 clicks\r\ndc.scroll(-5)\r\n\r\n# Scroll up 10 clicks\r\ndc.scroll(10)\r\n\r\n# Horizontal scroll\r\ndc.scroll(5, direction='horizontal')\r\n```\r\n\r\n#### `get_mouse_position()`\r\nGet current mouse coordinates.\r\n\r\n**Returns:** `(x, y)` tuple\r\n\r\n**Example:**\r\n```python\r\nx, y = dc.get_mouse_position()\r\nprint(f\"Mouse is at: {x}, {y}\")\r\n```\r\n\r\n---\r\n\r\n### Keyboard Functions\r\n\r\n#### `type_text(text, interval=0, wpm=None)`\r\nType text with configurable speed.\r\n\r\n**Parameters:**\r\n- `text` (str): Text to type\r\n- `interval` (float): Delay between keystrokes (0 = instant)\r\n- `wpm` (int, optional): Words per minute (overrides interval)\r\n\r\n**Example:**\r\n```python\r\n# Instant typing\r\ndc.type_text(\"Hello World\")\r\n\r\n# Human-like typing at 60 WPM\r\ndc.type_text(\"Hello World\", wpm=60)\r\n\r\n# Slow typing with 0.1s between keys\r\ndc.type_text(\"Hello World\", interval=0.1)\r\n```\r\n\r\n#### `press(key, presses=1, interval=0.1)`\r\nPress and release a key.\r\n\r\n**Parameters:**\r\n- `key` (str): Key name (see Key Names section)\r\n- `presses` (int): Number of times to press\r\n- `interval` (float): Delay between presses\r\n\r\n**Example:**\r\n```python\r\n# Press Enter\r\ndc.press('enter')\r\n\r\n# Press Space 3 times\r\ndc.press('space', presses=3)\r\n\r\n# Press Down arrow\r\ndc.press('down')\r\n```\r\n\r\n#### `hotkey(*keys, interval=0.05)`\r\nExecute keyboard shortcut.\r\n\r\n**Parameters:**\r\n- `*keys` (str): Keys to press together\r\n- `interval` (float): Delay between key presses\r\n\r\n**Example:**\r\n```python\r\n# Copy (Ctrl+C)\r\ndc.hotkey('ctrl', 'c')\r\n\r\n# Paste (Ctrl+V)\r\ndc.hotkey('ctrl', 'v')\r\n\r\n# Open Run dialog (Win+R)\r\ndc.hotkey('win', 'r')\r\n\r\n# Save (Ctrl+S)\r\ndc.hotkey('ctrl', 's')\r\n\r\n# Select All (Ctrl+A)\r\ndc.hotkey('ctrl', 'a')\r\n```\r\n\r\n#### `key_down(key)` / `key_up(key)`\r\nManually control key state.\r\n\r\n**Example:**\r\n```python\r\n# Hold Shift\r\ndc.key_down('shift')\r\ndc.type_text(\"hello\")  # Types \"HELLO\"\r\ndc.key_up('shift')\r\n\r\n# Hold Ctrl and click (for multi-select)\r\ndc.key_down('ctrl')\r\ndc.click(100, 100)\r\ndc.click(200, 100)\r\ndc.key_up('ctrl')\r\n```\r\n\r\n---\r\n\r\n### Screen Functions\r\n\r\n#### `screenshot(region=None, filename=None)`\r\nCapture screen or region.\r\n\r\n**Parameters:**\r\n- `region` (tuple, optional): (left, top, width, height) for partial capture\r\n- `filename` (str, optional): Path to save image\r\n\r\n**Returns:** PIL Image object\r\n\r\n**Example:**\r\n```python\r\n# Full screen\r\nimg = dc.screenshot()\r\n\r\n# Save to file\r\ndc.screenshot(filename=\"screenshot.png\")\r\n\r\n# Capture specific region\r\nimg = dc.screenshot(region=(100, 100, 500, 300))\r\n```\r\n\r\n#### `get_pixel_color(x, y)`\r\nGet color of pixel at coordinates.\r\n\r\n**Returns:** RGB tuple `(r, g, b)`\r\n\r\n**Example:**\r\n```python\r\nr, g, b = dc.get_pixel_color(500, 300)\r\nprint(f\"Color at (500, 300): RGB({r}, {g}, {b})\")\r\n```\r\n\r\n#### `find_on_screen(image_path, confidence=0.8)`\r\nFind image on screen (requires OpenCV).\r\n\r\n**Parameters:**\r\n- `image_path` (str): Path to template image\r\n- `confidence` (float): Match threshold (0-1)\r\n\r\n**Returns:** `(x, y, width, height)` or None\r\n\r\n**Example:**\r\n```python\r\n# Find button on screen\r\nlocation = dc.find_on_screen(\"button.png\")\r\nif location:\r\n    x, y, w, h = location\r\n    # Click center of found image\r\n    dc.click(x + w//2, y + h//2)\r\n```\r\n\r\n#### `get_screen_size()`\r\nGet screen resolution.\r\n\r\n**Returns:** `(width, height)` tuple\r\n\r\n**Example:**\r\n```python\r\nwidth, height = dc.get_screen_size()\r\nprint(f\"Screen: {width}x{height}\")\r\n```\r\n\r\n---\r\n\r\n### Window Functions\r\n\r\n#### `get_all_windows()`\r\nList all open windows.\r\n\r\n**Returns:** List of window titles\r\n\r\n**Example:**\r\n```python\r\nwindows = dc.get_all_windows()\r\nfor title in windows:\r\n    print(f\"Window: {title}\")\r\n```\r\n\r\n#### `activate_window(title_substring)`\r\nBring window to front by title.\r\n\r\n**Parameters:**\r\n- `title_substring` (str): Part of window title to match\r\n\r\n**Example:**\r\n```python\r\n# Activate Chrome\r\ndc.activate_window(\"Chrome\")\r\n\r\n# Activate VS Code\r\ndc.activate_window(\"Visual Studio Code\")\r\n```\r\n\r\n#### `get_active_window()`\r\nGet currently focused window.\r\n\r\n**Returns:** Window title (str)\r\n\r\n**Example:**\r\n```python\r\nactive = dc.get_active_window()\r\nprint(f\"Active window: {active}\")\r\n```\r\n\r\n---\r\n\r\n### Clipboard Functions\r\n\r\n#### `copy_to_clipboard(text)`\r\nCopy text to clipboard.\r\n\r\n**Example:**\r\n```python\r\ndc.copy_to_clipboard(\"Hello from OpenClaw!\")\r\n```\r\n\r\n#### `get_from_clipboard()`\r\nGet text from clipboard.\r\n\r\n**Returns:** str\r\n\r\n**Example:**\r\n```python\r\ntext = dc.get_from_clipboard()\r\nprint(f\"Clipboard: {text}\")\r\n```\r\n\r\n---\r\n\r\n## ⌨️ Key Names Reference\r\n\r\n### Alphabet Keys\r\n`'a'` through `'z'`\r\n\r\n### Number Keys\r\n`'0'` through `'9'`\r\n\r\n### Function Keys\r\n`'f1'` through `'f24'`\r\n\r\n### Special Keys\r\n- `'enter'` / `'return'`\r\n- `'esc'` / `'escape'`\r\n- `'space'` / `'spacebar'`\r\n- `'tab'`\r\n- `'backspace'`\r\n- `'delete'` / `'del'`\r\n- `'insert'`\r\n- `'home'`\r\n- `'end'`\r\n- `'pageup'` / `'pgup'`\r\n- `'pagedown'` / `'pgdn'`\r\n\r\n### Arrow Keys\r\n- `'up'` / `'down'` / `'left'` / `'right'`\r\n\r\n### Modifier Keys\r\n- `'ctrl'` / `'control'`\r\n- `'shift'`\r\n- `'alt'`\r\n- `'win'` / `'winleft'` / `'winright'`\r\n- `'cmd'` / `'command'` (Mac)\r\n\r\n### Lock Keys\r\n- `'capslock'`\r\n- `'numlock'`\r\n- `'scrolllock'`\r\n\r\n### Punctuation\r\n- `'.'` / `','` / `'?'` / `'!'` / `';'` / `':'`\r\n- `'['` / `']'` / `'{'` / `'}'`\r\n- `'('` / `')'`\r\n- `'+'` / `'-'` / `'*'` / `'/'` / `'='`\r\n\r\n---\r\n\r\n## πŸ›‘οΈ Safety Features\r\n\r\n### Failsafe Mode\r\n\r\nMove mouse to **any corner** of the screen to abort all automation.\r\n\r\n```python\r\n# Enable failsafe (enabled by default)\r\ndc = DesktopController(failsafe=True)\r\n```\r\n\r\n### Pause Control\r\n\r\n```python\r\n# Pause all automation for 2 seconds\r\ndc.pause(2.0)\r\n\r\n# Check if automation is safe to proceed\r\nif dc.is_safe():\r\n    dc.click(500, 500)\r\n```\r\n\r\n### Approval Mode\r\n\r\nRequire user confirmation before actions:\r\n\r\n```python\r\ndc = DesktopController(require_approval=True)\r\n\r\n# This will ask for confirmation\r\ndc.click(500, 500)  # Prompt: \"Allow click at (500, 500)? [y/n]\"\r\n```\r\n\r\n---\r\n\r\n## 🎨 Advanced Examples\r\n\r\n### Example 1: Automated Form Filling\r\n\r\n```python\r\ndc = DesktopController()\r\n\r\n# Click name field\r\ndc.click(300, 200)\r\ndc.type_text(\"John Doe\", wpm=80)\r\n\r\n# Tab to next field\r\ndc.press('tab')\r\ndc.type_text(\"john@example.com\", wpm=80)\r\n\r\n# Tab to password\r\ndc.press('tab')\r\ndc.type_text(\"SecurePassword123\", wpm=60)\r\n\r\n# Submit form\r\ndc.press('enter')\r\n```\r\n\r\n### Example 2: Screenshot Region and Save\r\n\r\n```python\r\n# Capture specific area\r\nregion = (100, 100, 800, 600)  # left, top, width, height\r\nimg = dc.screenshot(region=region)\r\n\r\n# Save with timestamp\r\nimport datetime\r\ntimestamp = datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")\r\nimg.save(f\"capture_{timestamp}.png\")\r\n```\r\n\r\n### Example 3: Multi-File Selection\r\n\r\n```python\r\n# Hold Ctrl and click multiple files\r\ndc.key_down('ctrl')\r\ndc.click(100, 200)  # First file\r\ndc.click(100, 250)  # Second file\r\ndc.click(100, 300)  # Third file\r\ndc.key_up('ctrl')\r\n\r\n# Copy selected files\r\ndc.hotkey('ctrl', 'c')\r\n```\r\n\r\n### Example 4: Window Automation\r\n\r\n```python\r\n# Activate Calculator\r\ndc.activate_window(\"Calculator\")\r\ntime.sleep(0.5)\r\n\r\n# Type calculation\r\ndc.type_text(\"5+3=\", interval=0.2)\r\ntime.sleep(0.5)\r\n\r\n# Take screenshot of result\r\ndc.screenshot(filename=\"calculation_result.png\")\r\n```\r\n\r\n### Example 5: Drag & Drop File\r\n\r\n```python\r\n# Drag file from source to destination\r\ndc.drag(\r\n    start_x=200, start_y=300,  # File location\r\n    end_x=800, end_y=500,       # Folder location\r\n    duration=1.0                 # Smooth 1-second drag\r\n)\r\n```\r\n\r\n---\r\n\r\n## ⚑ Performance Tips\r\n\r\n1. **Use instant movements** for speed: `duration=0`\r\n2. **Batch operations** instead of individual calls\r\n3. **Cache screen positions** instead of recalculating\r\n4. **Disable failsafe** for maximum performance (use with caution)\r\n5. **Use hotkeys** instead of menu navigation\r\n\r\n---\r\n\r\n## ⚠️ Important Notes\r\n\r\n- **Screen coordinates** start at (0, 0) in top-left corner\r\n- **Multi-monitor setups** may have negative coordinates for secondary displays\r\n- **Windows DPI scaling** may affect coordinate accuracy\r\n- **Failsafe corners** are: (0,0), (width-1, 0), (0, height-1), (width-1, height-1)\r\n- **Some applications** may block simulated input (games, secure apps)\r\n\r\n---\r\n\r\n## πŸ”§ Troubleshooting\r\n\r\n### Mouse not moving to correct position\r\n- Check DPI scaling settings\r\n- Verify screen resolution matches expectations\r\n- Use `get_screen_size()` to confirm dimensions\r\n\r\n### Keyboard input not working\r\n- Ensure target application has focus\r\n- Some apps require admin privileges\r\n- Try increasing `interval` for reliability\r\n\r\n### Failsafe triggering accidentally\r\n- Increase screen border tolerance\r\n- Move mouse away from corners during normal use\r\n- Disable if needed: `DesktopController(failsafe=False)`\r\n\r\n### Permission errors\r\n- Run Python with administrator privileges for some operations\r\n- Some secure applications block automation\r\n\r\n---\r\n\r\n## πŸ“¦ Dependencies\r\n\r\n- **PyAutoGUI** - Core automation engine\r\n- **Pillow** - Image processing\r\n- **OpenCV** (optional) - Image recognition\r\n- **PyGetWindow** - Window management\r\n\r\nInstall all:\r\n```bash\r\npip install pyautogui pillow opencv-python pygetwindow\r\n```\r\n\r\n---\r\n\r\n**Built for OpenClaw** - The ultimate desktop automation companion 🦞\r\n"
  }
}

Versions

VersionSizeUpdated1.0.0Not availableFeb 05, 2026