mirror of
https://github.com/trycua/computer.git
synced 2026-01-08 06:20:00 -06:00
added correct example
This commit is contained in:
@@ -42,17 +42,28 @@ async def main():
|
||||
ephemeral=False,
|
||||
)
|
||||
|
||||
# computer = Computer(
|
||||
# os_type="linux",
|
||||
# api_key=os.getenv("CUA_API_KEY"),
|
||||
# name=os.getenv("VM_NAME"),
|
||||
# provider_type=VMProviderType.CLOUD,
|
||||
# )
|
||||
|
||||
try:
|
||||
# Run the computer with default parameters
|
||||
await computer.run()
|
||||
|
||||
await computer.interface.hotkey("command", "space")
|
||||
screenshot = await computer.interface.screenshot()
|
||||
with open(Path("~/cua/examples/screenshot.png").expanduser(), "wb") as f:
|
||||
f.write(screenshot)
|
||||
|
||||
# await computer.interface.hotkey("command", "space")
|
||||
|
||||
# res = await computer.interface.run_command("touch ./Downloads/empty_file")
|
||||
# print(f"Run command result: {res}")
|
||||
|
||||
accessibility_tree = await computer.interface.get_accessibility_tree()
|
||||
print(f"Accessibility tree: {accessibility_tree}")
|
||||
# accessibility_tree = await computer.interface.get_accessibility_tree()
|
||||
# print(f"Accessibility tree: {accessibility_tree}")
|
||||
|
||||
# Screen Actions Examples
|
||||
# print("\n=== Screen Actions ===")
|
||||
@@ -60,36 +71,36 @@ async def main():
|
||||
# with open("screenshot_direct.png", "wb") as f:
|
||||
# f.write(screenshot)
|
||||
|
||||
screen_size = await computer.interface.get_screen_size()
|
||||
print(f"Screen size: {screen_size}")
|
||||
# screen_size = await computer.interface.get_screen_size()
|
||||
# print(f"Screen size: {screen_size}")
|
||||
|
||||
# Demonstrate coordinate conversion
|
||||
center_x, center_y = 733, 736
|
||||
print(f"Center in screen coordinates: ({center_x}, {center_y})")
|
||||
# center_x, center_y = 733, 736
|
||||
# print(f"Center in screen coordinates: ({center_x}, {center_y})")
|
||||
|
||||
screenshot_center = await computer.to_screenshot_coordinates(center_x, center_y)
|
||||
print(f"Center in screenshot coordinates: {screenshot_center}")
|
||||
# screenshot_center = await computer.to_screenshot_coordinates(center_x, center_y)
|
||||
# print(f"Center in screenshot coordinates: {screenshot_center}")
|
||||
|
||||
screen_center = await computer.to_screen_coordinates(*screenshot_center)
|
||||
print(f"Back to screen coordinates: {screen_center}")
|
||||
# screen_center = await computer.to_screen_coordinates(*screenshot_center)
|
||||
# print(f"Back to screen coordinates: {screen_center}")
|
||||
|
||||
# Mouse Actions Examples
|
||||
print("\n=== Mouse Actions ===")
|
||||
await computer.interface.move_cursor(100, 100)
|
||||
await computer.interface.left_click()
|
||||
await computer.interface.right_click(300, 300)
|
||||
await computer.interface.double_click(400, 400)
|
||||
# print("\n=== Mouse Actions ===")
|
||||
# await computer.interface.move_cursor(100, 100)
|
||||
# await computer.interface.left_click()
|
||||
# await computer.interface.right_click(300, 300)
|
||||
# await computer.interface.double_click(400, 400)
|
||||
|
||||
# Keyboard Actions Examples
|
||||
print("\n=== Keyboard Actions ===")
|
||||
await computer.interface.type_text("Hello, World!")
|
||||
await computer.interface.press_key("enter")
|
||||
# # Keyboard Actions Examples
|
||||
# print("\n=== Keyboard Actions ===")
|
||||
# await computer.interface.type_text("Hello, World!")
|
||||
# await computer.interface.press_key("enter")
|
||||
|
||||
# Clipboard Actions Examples
|
||||
print("\n=== Clipboard Actions ===")
|
||||
await computer.interface.set_clipboard("Test clipboard")
|
||||
content = await computer.interface.copy_to_clipboard()
|
||||
print(f"Clipboard content: {content}")
|
||||
# # Clipboard Actions Examples
|
||||
# print("\n=== Clipboard Actions ===")
|
||||
# await computer.interface.set_clipboard("Test clipboard")
|
||||
# content = await computer.interface.copy_to_clipboard()
|
||||
# print(f"Clipboard content: {content}")
|
||||
|
||||
finally:
|
||||
# Important to clean up resources
|
||||
|
||||
Reference in New Issue
Block a user