Class: Daytona::ComputerUse::Mouse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Instrumentation

included

Constructor Details

#initialize(sandbox_id:, toolbox_api:, otel_state: nil) ⇒ 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

  • otel_state (Daytona::OtelState, nil) (defaults to: nil)


17
18
19
20
21
# File 'lib/daytona/computer_use.rb', line 17

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

Instance Attribute Details

#sandbox_idString (readonly)

Returns The ID of the sandbox.

Returns:

  • (String)

    The ID of the sandbox



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

def sandbox_id
  @sandbox_id
end

#toolbox_apiDaytonaToolboxApiClient::ComputerUseApi (readonly)

Returns API client for sandbox operations.

Returns:

  • (DaytonaToolboxApiClient::ComputerUseApi)

    API client for sandbox operations



12
13
14
# File 'lib/daytona/computer_use.rb', line 12

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:



72
73
74
75
76
77
# File 'lib/daytona/computer_use.rb', line 72

def click(x:, y:, button: 'left', double: false)
  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:



92
93
94
95
96
97
# File 'lib/daytona/computer_use.rb', line 92

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:



47
48
49
50
51
52
# File 'lib/daytona/computer_use.rb', line 47

def move(x:, y:)
  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:



31
32
33
34
35
# File 'lib/daytona/computer_use.rb', line 31

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:



114
115
116
117
118
119
120
# File 'lib/daytona/computer_use.rb', line 114

def scroll(x:, y:, direction:, amount: 1)
  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