Class: Daytona::ComputerUse::Mouse

Inherits:
Object
  • Object
show all
Defined in:
lib/daytona/computer_use.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sandbox_id:, toolbox_api:) ⇒ Mouse

Returns a new instance of Mouse.

Parameters:

  • sandbox_id (String)

    The ID of the sandbox

  • toolbox_api (DaytonaToolboxApiClient::ComputerUseApi)

    API client for sandbox operations



14
15
16
17
# File 'lib/daytona/computer_use.rb', line 14

def initialize(sandbox_id:, toolbox_api:)
  @sandbox_id = sandbox_id
  @toolbox_api = toolbox_api
end

Instance Attribute Details

#sandbox_idString (readonly)

Returns The ID of the sandbox.

Returns:

  • (String)

    The ID of the sandbox



7
8
9
# File 'lib/daytona/computer_use.rb', line 7

def sandbox_id
  @sandbox_id
end

#toolbox_apiDaytonaToolboxApiClient::ComputerUseApi (readonly)

Returns API client for sandbox operations.

Returns:

  • (DaytonaToolboxApiClient::ComputerUseApi)

    API client for sandbox operations



10
11
12
# File 'lib/daytona/computer_use.rb', line 10

def toolbox_api
  @toolbox_api
end

Instance Method Details

#click(x:, y:, button: 'left', double: false) ⇒ DaytonaToolboxApiClient::MouseClickResponse

Clicks the mouse at the specified coordinates.

Examples:

# Single left click
result = sandbox.computer_use.mouse.click(x: 100, y: 200)

# Double click
double_click = sandbox.computer_use.mouse.click(x: 100, y: 200, button: 'left', double: true)

# Right click
right_click = sandbox.computer_use.mouse.click(x: 100, y: 200, button: 'right')

Parameters:

  • x (Integer)

    The x coordinate to click at

  • y (Integer)

    The y coordinate to click at

  • button (String) (defaults to: 'left')

    The mouse button to click (‘left’, ‘right’, ‘middle’). Defaults to ‘left’

  • double (Boolean) (defaults to: false)

    Whether to perform a double-click. Defaults to false

Returns:

  • (DaytonaToolboxApiClient::MouseClickResponse)

    Click operation result

Raises:



68
69
70
71
72
73
# File 'lib/daytona/computer_use.rb', line 68

def click(x:, y:, button: 'left', double: false) # rubocop:disable Naming/MethodParameterName
  request = DaytonaToolboxApiClient::MouseClickRequest.new(x:, y:, button:, double:)
  toolbox_api.click(request)
rescue StandardError => e
  raise Sdk::Error, "Failed to click mouse: #{e.message}"
end

#drag(start_x:, start_y:, end_x:, end_y:, button: 'left') ⇒ DaytonaToolboxApiClient::MouseDragResponse

Drags the mouse from start coordinates to end coordinates.

Examples:

result = sandbox.computer_use.mouse.drag(start_x: 50, start_y: 50, end_x: 150, end_y: 150)
puts "Dragged from #{result.from_x},#{result.from_y} to #{result.to_x},#{result.to_y}"

Parameters:

  • start_x (Integer)

    The starting x coordinate

  • start_y (Integer)

    The starting y coordinate

  • end_x (Integer)

    The ending x coordinate

  • end_y (Integer)

    The ending y coordinate

  • button (String) (defaults to: 'left')

    The mouse button to use for dragging. Defaults to ‘left’

Returns:

  • (DaytonaToolboxApiClient::MouseDragResponse)

    Drag operation result

Raises:



88
89
90
91
92
93
# File 'lib/daytona/computer_use.rb', line 88

def drag(start_x:, start_y:, end_x:, end_y:, button: 'left')
  request = DaytonaToolboxApiClient::MouseDragRequest.new(start_x:, start_y:, end_x:, end_y:, button:)
  toolbox_api.drag(request)
rescue StandardError => e
  raise Sdk::Error, "Failed to drag mouse: #{e.message}"
end

#move(x:, y:) ⇒ DaytonaToolboxApiClient::MouseMoveResponse

Moves the mouse cursor to the specified coordinates.

Examples:

result = sandbox.computer_use.mouse.move(x: 100, y: 200)
puts "Mouse moved to: #{result.x}, #{result.y}"

Parameters:

  • x (Integer)

    The x coordinate to move to

  • y (Integer)

    The y coordinate to move to

Returns:

  • (DaytonaToolboxApiClient::MouseMoveResponse)

    Move operation result

Raises:



43
44
45
46
47
48
# File 'lib/daytona/computer_use.rb', line 43

def move(x:, y:) # rubocop:disable Naming/MethodParameterName
  request = DaytonaToolboxApiClient::MouseMoveRequest.new(x:, y:)
  toolbox_api.move_mouse(request)
rescue StandardError => e
  raise Sdk::Error, "Failed to move mouse: #{e.message}"
end

#positionDaytonaToolboxApiClient::MousePosition

Gets the current mouse cursor position.

Examples:

position = sandbox.computer_use.mouse.get_position
puts "Mouse is at: #{position.x}, #{position.y}"

Returns:

  • (DaytonaToolboxApiClient::MousePosition)

    Current mouse position with x and y coordinates

Raises:



27
28
29
30
31
# File 'lib/daytona/computer_use.rb', line 27

def position
  toolbox_api.get_mouse_position
rescue StandardError => e
  raise Sdk::Error, "Failed to get mouse position: #{e.message}"
end

#scroll(x:, y:, direction:, amount: 1) ⇒ Boolean

Scrolls the mouse wheel at the specified coordinates.

Examples:

# Scroll up
scroll_up = sandbox.computer_use.mouse.scroll(x: 100, y: 200, direction: 'up', amount: 3)

# Scroll down
scroll_down = sandbox.computer_use.mouse.scroll(x: 100, y: 200, direction: 'down', amount: 5)

Parameters:

  • x (Integer)

    The x coordinate to scroll at

  • y (Integer)

    The y coordinate to scroll at

  • direction (String)

    The direction to scroll (‘up’ or ‘down’)

  • amount (Integer) (defaults to: 1)

    The amount to scroll. Defaults to 1

Returns:

  • (Boolean)

    Whether the scroll operation was successful

Raises:



110
111
112
113
114
115
116
# File 'lib/daytona/computer_use.rb', line 110

def scroll(x:, y:, direction:, amount: 1) # rubocop:disable Naming/MethodParameterName
  request = DaytonaToolboxApiClient::MouseScrollRequest.new(x:, y:, direction:, amount:)
  toolbox_api.scroll(request)
  true
rescue StandardError => e
  raise Sdk::Error, "Failed to scroll mouse: #{e.message}"
end