Computer
Screenshots, pointer, keyboard, clipboard and displays of a sandbox desktop through cua-spacesd.
Screenshots, pointer, keyboard, clipboard and displays of a sandbox desktop through cua-spacesd.
Coordinates are screen pixels. cua-spacesd delegates input to Cua Driver in the guest; these calls need an image with a desktop.
Python programs usually use the high-level API instead: sb.mouse, sb.keyboard, sb.screen.
Methods of SpacesdClient.
SpacesdClient.screenshot#Captures a display.
async def screenshot(self, options: Optional[ScreenshotOptions]) -> Screenshot| Parameter | Type | Default |
|---|---|---|
options | Option<ScreenshotOptions> | required |
Returns Screenshot · Async · Raises CuaError
Example
import asyncio
import cua
async def main():
guest = await cua.embedded().spacesd(URL, TOKEN)
shot = await guest.screenshot(None) # PNG by default
await guest.click(shot.width / 2, shot.height / 2)
print([shot.width > 0, shot.image[:4]])
# [True, b'\x89PNG']
asyncio.run(main())SpacesdClient.click#Left click.
async def click(self, x: float, y: float) -> None| Parameter | Type | Default |
|---|---|---|
x | f64 | required |
y | f64 | required |
Async · Raises CuaError
SpacesdClient.double_click#Double click.
async def double_click(self, x: float, y: float) -> None| Parameter | Type | Default |
|---|---|---|
x | f64 | required |
y | f64 | required |
Async · Raises CuaError
SpacesdClient.right_click#Right click.
async def right_click(self, x: float, y: float) -> None| Parameter | Type | Default |
|---|---|---|
x | f64 | required |
y | f64 | required |
Async · Raises CuaError
SpacesdClient.move_to#Moves the pointer.
async def move_to(self, x: float, y: float) -> None| Parameter | Type | Default |
|---|---|---|
x | f64 | required |
y | f64 | required |
Async · Raises CuaError
SpacesdClient.drag#Drags with the left button.
async def drag(self, from_x: float, from_y: float, to_x: float, to_y: float) -> None| Parameter | Type | Default |
|---|---|---|
from_x | f64 | required |
from_y | f64 | required |
to_x | f64 | required |
to_y | f64 | required |
Async · Raises CuaError
SpacesdClient.scroll#Scrolls by line deltas.
async def scroll(self, dx: float, dy: float) -> None| Parameter | Type | Default |
|---|---|---|
dx | f64 | required |
dy | f64 | required |
Async · Raises CuaError
SpacesdClient.type_text#Types text.
async def type_text(self, text: str) -> None| Parameter | Type | Default |
|---|---|---|
text | String | required |
Async · Raises CuaError
SpacesdClient.press#Presses one key (enter, KEY_ESCAPE, a, ...).
async def press(self, key: str) -> None| Parameter | Type | Default |
|---|---|---|
key | String | required |
Async · Raises CuaError
SpacesdClient.hotkey#Presses a chord (["ctrl", "c"]).
async def hotkey(self, keys: List[str]) -> None| Parameter | Type | Default |
|---|---|---|
keys | Vec<String> | required |
Async · Raises CuaError
SpacesdClient.pointer_json#Full ComputerService.Pointer from proto3 JSON.
async def pointer_json(self, request_json: str) -> str| Parameter | Type | Default |
|---|---|---|
request_json | String | required |
Returns String · Async · Raises CuaError
SpacesdClient.keyboard_json#Full ComputerService.Keyboard from proto3 JSON.
async def keyboard_json(self, request_json: str) -> str| Parameter | Type | Default |
|---|---|---|
request_json | String | required |
Returns String · Async · Raises CuaError
SpacesdClient.get_clipboard#Clipboard text.
async def get_clipboard(self) -> Optional[str]Returns Option<String> · Async · Raises CuaError
SpacesdClient.set_clipboard#Sets clipboard text; returns the clipboard generation.
async def set_clipboard(self, text: str) -> int| Parameter | Type | Default |
|---|---|---|
text | String | required |
Returns u64 · Async · Raises CuaError
SpacesdClient.cursor_position#Pointer position.
async def cursor_position(self) -> PointReturns Point · Async · Raises CuaError
SpacesdClient.displays#Displays as proto3 JSON ([Display]).
async def displays(self) -> strReturns String · Async · Raises CuaError
Screenshot record#A captured screenshot.
Returned by Sandbox.guest_screenshot, Space.screenshot, SpacesdClient.screenshot.
| Field | Type | Default | Description |
|---|---|---|---|
image | Vec<u8> | Encoded image. | |
format | ImageFormat | Encoding. | |
width | u32 | Pixel width. | |
height | u32 | Pixel height. | |
scale | f64 | Image pixels per logical point. | |
screenshot_id / screenshotId | String | Id for screenshot-space input. |
ScreenshotOptions record#Screenshot options.
| Field | Type | Default | Description |
|---|---|---|---|
display | Option<String> | None | Display id (primary when unset). |
format | Option<ImageFormat> | None | Encoding (PNG when unset). |
quality | Option<u32> | None | Lossy quality 1–100. |
max_dimension / maxDimension | Option<u32> | None | Long-edge cap in pixels. |
include_cursor / includeCursor | bool | false | Draw the cursor. |
ImageFormat enum#Screenshot encoding.
ImageFormat.PNG
ImageFormat.JPEG
ImageFormat.WEBP| Variant | Description |
|---|---|
Png | PNG. |
Jpeg | JPEG. |
Webp | WebP. |
Point record#A point.
Returned by SpacesdClient.cursor_position.
| Field | Type | Default | Description |
|---|---|---|---|
x | f64 | X. | |
y | f64 | Y. |