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

Screenshot and display

from nullspace import Sandbox

with Sandbox.create(
    template="desktop",
    timeout=300,
    resolution=(1440, 900),
    dpi=144,
) as sandbox:
    png = sandbox.desktop.screenshot()
    width, height = sandbox.desktop.screen_size()
    display = sandbox.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 = sandbox.desktop.screenshot_region(0, 0, 400, 300)
jpeg = sandbox.desktop.screenshot_compressed(
    format="jpeg",
    quality=70,
    scale=0.5,
    show_cursor=True,
    region=(0, 0, 800, 600),
)

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

Mouse and keyboard

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

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

Windows and clipboard

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

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

sandbox.desktop.set_clipboard_text("copied from sdk")
print(sandbox.desktop.get_clipboard_text())

Launch and open

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