CUA Auto

0.1.2 · active · verified Sun Apr 12

cua-auto is the Python client library for interacting with the CUA computer server, enabling cross-platform automation of mouse, keyboard, screen, window, clipboard, and shell operations. It is currently at version 0.1.2, with the larger CUA ecosystem seeing more frequent updates across its modular components (server, sandbox).

Warnings

Install

Imports

Quickstart

This quickstart demonstrates connecting to a CUA computer server and performing basic mouse and keyboard actions. It's crucial to have a `cua-computer-server` instance running on the specified host and port for this client library to function.

import os
from cua_auto import CuaClient

# The CuaClient connects to a running CUA computer server.
# Ensure 'cua-computer-server' is running on the specified host and port.
# For local testing, you might need to start it separately.
host = os.environ.get("CUA_SERVER_HOST", "localhost")
port = int(os.environ.get("CUA_SERVER_PORT", 1337))

try:
    client = CuaClient(host=host, port=port)
    print(f"Connected to CUA server at {host}:{port}")

    # Example: Get screen size
    screen_size = client.screen.get_size()
    print(f"Screen size: {screen_size.width}x{screen_size.height}")

    # Example: Move mouse relative to current position
    client.mouse.move_relative(100, 50)
    print("Moved mouse by 100, 50 pixels.")

    # Example: Type text
    client.keyboard.type("Hello from cua-auto!")
    print("Typed 'Hello from cua-auto!'.")

except ConnectionRefusedError:
    print(f"Error: Connection to CUA server at {host}:{port} refused.")
    print("Please ensure the 'cua-computer-server' is running and accessible.")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →