Skip to main content
Desktop APIs require a desktop-capable template such as desktop.

Screenshot and display

from nullspace import Machine

with Machine.create(
    template="desktop",
    timeout=300,
    resolution=(1440, 900),
    dpi=144,
) as machine:
    png = machine.desktop.screenshot()
    width, height = machine.desktop.screen_size()
    display = machine.desktop.display_info()
    print(len(png), width, height)
    print(display.virtual_screen.width, display.virtual_screen.height)

    for monitor in display.monitors:
        print(monitor.id, monitor.width, monitor.height, monitor.is_primary)

Regions and compressed screenshots

region_png = machine.desktop.screenshot_region(0, 0, 400, 300)
jpeg = machine.desktop.screenshot_compressed(
    format="jpeg",
    quality=70,
    scale=0.5,
    show_cursor=True,
    region=(0, 0, 800, 600),
)

caps = machine.desktop.capabilities()
print(caps.capture.compressed_formats)

Mouse and keyboard

machine.desktop.move(100, 100)
machine.desktop.click(100, 100)
machine.desktop.left_click()
machine.desktop.right_click(100, 100)
machine.desktop.mouse_press("left", 100, 100)
machine.desktop.mouse_release("left", 300, 300)
machine.desktop.double_click(200, 200)
machine.desktop.drag(100, 100, 300, 300)
machine.desktop.scroll(400, 400, "down", amount=3)

machine.desktop.type("hello world")
machine.desktop.key("Return")
machine.desktop.hotkey("ctrl+a")
machine.desktop.press("c", modifiers=["ctrl"])

Windows and clipboard

for window in machine.desktop.list_windows():
    print(window.id, window.title)

current = machine.desktop.get_current_window_id()
print(machine.desktop.get_window_title(current))

machine.desktop.set_clipboard_text("copied from sdk")
print(machine.desktop.get_clipboard_text())
The window title route is read-only (GET /desktop/window/{window_id}/title). There is no endpoint or command to set a window title. The pointer position and per-deployment capability matrix are also read-only surfaces:
x, y = machine.desktop.cursor_position()
caps = machine.desktop.capabilities()
print(x, y, caps.capture.compressed_formats)

Launch and open

machine.desktop.launch_executable("xterm")
machine.desktop.launch_desktop_entry("firefox.desktop", uri="https://example.com")
machine.desktop.open("https://example.com")