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)


146
147
148
149
150
# File 'lib/daytona/computer_use.rb', line 146

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



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

def sandbox_id
  @sandbox_id
end

#toolbox_apiDaytonaToolboxApiClient::ComputerUseApi (readonly)

Returns API client for sandbox operations.

Returns:

  • (DaytonaToolboxApiClient::ComputerUseApi)

    API client for sandbox operations



141
142
143
# File 'lib/daytona/computer_use.rb', line 141

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)

    A single atomic hotkey chord (e.g., ‘ctrl+c’, ‘alt+tab’, ‘cmd+shift+t’, ‘ctrl + c’, ‘shift’). Uses the same normalized key contract as #press.

Raises:



209
210
211
212
213
214
# File 'lib/daytona/computer_use.rb', line 209

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("enter")

# 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. Canonical names include ‘enter’, ‘escape’, ‘tab’, letters, digits, unshifted punctuation, function keys, and grammar-safe numpad names such as ‘num_plus’. Named keys are case-insensitive, and common aliases such as ‘Return’ and ‘Escape’ are normalized.

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

    Canonical modifier names are ‘ctrl’, ‘alt’, ‘shift’, and ‘cmd’. Common aliases such as ‘control’, ‘option’, ‘meta’, and ‘win’ are normalized.

Raises:



187
188
189
190
191
192
# File 'lib/daytona/computer_use.rb', line 187

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:



164
165
166
167
168
169
# File 'lib/daytona/computer_use.rb', line 164

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