Class: Daytona::ComputerUse::Keyboard

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

Overview

Keyboard operations for computer use functionality.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Instrumentation

included

Constructor Details

#initialize(sandbox_id:, toolbox_api:, otel_state: nil) ⇒ Keyboard

Returns a new instance of Keyboard.

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)


143
144
145
146
147
# File 'lib/daytona/computer_use.rb', line 143

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



135
136
137
# File 'lib/daytona/computer_use.rb', line 135

def sandbox_id
  @sandbox_id
end

#toolbox_apiDaytonaToolboxApiClient::ComputerUseApi (readonly)

Returns API client for sandbox operations.

Returns:

  • (DaytonaToolboxApiClient::ComputerUseApi)

    API client for sandbox operations



138
139
140
# File 'lib/daytona/computer_use.rb', line 138

def toolbox_api
  @toolbox_api
end

Instance Method Details

#hotkey(keys:) ⇒ void

This method returns an undefined value.

Presses a hotkey combination.

Examples:

# Copy
sandbox.computer_use.keyboard.hotkey("ctrl+c")

# Paste
sandbox.computer_use.keyboard.hotkey("ctrl+v")

# Alt+Tab
sandbox.computer_use.keyboard.hotkey("alt+tab")

Parameters:

  • keys (String)

    The hotkey combination (e.g., ‘ctrl+c’, ‘alt+tab’, ‘cmd+shift+t’)

Raises:



206
207
208
209
210
211
# File 'lib/daytona/computer_use.rb', line 206

def hotkey(keys:)
  request = DaytonaToolboxApiClient::KeyboardHotkeyRequest.new(keys:)
  toolbox_api.press_hotkey(request)
rescue StandardError => e
  raise Sdk::Error, "Failed to press hotkey: #{e.message}"
end

#press(key:, modifiers: nil) ⇒ void

This method returns an undefined value.

Presses a key with optional modifiers.

Examples:

# Press Enter
sandbox.computer_use.keyboard.press("Return")

# Press Ctrl+C
sandbox.computer_use.keyboard.press("c", modifiers: ["ctrl"])

# Press Ctrl+Shift+T
sandbox.computer_use.keyboard.press("t", modifiers: ["ctrl", "shift"])

Parameters:

  • key (String)

    The key to press (e.g., ‘Enter’, ‘Escape’, ‘Tab’, ‘a’, ‘A’)

  • modifiers (Array<String>, nil) (defaults to: nil)

    Modifier keys (‘ctrl’, ‘alt’, ‘meta’, ‘shift’)

Raises:



184
185
186
187
188
189
# File 'lib/daytona/computer_use.rb', line 184

def press(key:, modifiers: nil)
  request = DaytonaToolboxApiClient::KeyboardPressRequest.new(key:, modifiers: modifiers || [])
  toolbox_api.press_key(request)
rescue StandardError => e
  raise Sdk::Error, "Failed to press key: #{e.message}"
end

#type(text:, delay: nil) ⇒ void

This method returns an undefined value.

Types the specified text.

Examples:

sandbox.computer_use.keyboard.type("Hello, World!")

# With delay between characters
sandbox.computer_use.keyboard.type("Slow typing", delay: 100)

Parameters:

  • text (String)

    The text to type

  • delay (Integer, nil) (defaults to: nil)

    Delay between characters in milliseconds

Raises:



161
162
163
164
165
166
# File 'lib/daytona/computer_use.rb', line 161

def type(text:, delay: nil)
  request = DaytonaToolboxApiClient::KeyboardTypeRequest.new(text:, delay:)
  toolbox_api.type_text(request)
rescue StandardError => e
  raise Sdk::Error, "Failed to type text: #{e.message}"
end