Skip to main content
Control keyboard input to type text, press keys, and execute key combinations for desktop automation.

Overview

Keyboard control enables:
  • Typing text into applications
  • Pressing individual keys
  • Executing key combinations (Ctrl+C, Alt+Tab, etc.)
  • Simulating keyboard shortcuts
Desktop automation requires a template with desktop support. Ensure your sandbox has desktop capabilities enabled.

Typing Text

Type text as if typed on a keyboard:
  • Python
  • JavaScript
from hopx_ai import Sandbox

sandbox = Sandbox.create(template="desktop")

# Type text
sandbox.desktop.type("Hello, World!")

# Type with custom delay between keystrokes
sandbox.desktop.type("Slow typing", delay_ms=50)

Pressing Keys

Press individual keys:
  • Python
  • JavaScript
# Press Enter
sandbox.desktop.press("Return")

# Press Escape
sandbox.desktop.press("Escape")

# Press Tab
sandbox.desktop.press("Tab")

# Press function keys
sandbox.desktop.press("F1")
sandbox.desktop.press("F5")

Key Combinations

Execute key combinations (modifier keys + main key):
  • Python
  • JavaScript
# Ctrl+C (copy)
sandbox.desktop.combination(['ctrl'], 'c')

# Ctrl+V (paste)
sandbox.desktop.combination(['ctrl'], 'v')

# Ctrl+Shift+T (new tab)
sandbox.desktop.combination(['ctrl', 'shift'], 't')

# Alt+F4 (close window)
sandbox.desktop.combination(['alt'], 'F4')

# Ctrl+Alt+Delete
sandbox.desktop.combination(['ctrl', 'alt'], 'Delete')

Available Keys

Common key names:
  • Modifiers: 'ctrl', 'shift', 'alt', 'meta' (Command on macOS)
  • Function keys: 'F1' through 'F12'
  • Special keys: 'Return' (Enter), 'Escape', 'Tab', 'Backspace', 'Delete'
  • Arrow keys: 'Up', 'Down', 'Left', 'Right'
  • Letters and numbers: 'a', 'b', '1', '2', etc.

Typing Speed

Control typing speed with delay:
  • Python
  • JavaScript
# Fast typing (default: 10ms delay)
sandbox.desktop.type("Fast text", delay_ms=10)

# Normal typing
sandbox.desktop.type("Normal text", delay_ms=50)

# Slow typing (for debugging)
sandbox.desktop.type("Slow text", delay_ms=100)

Complete Example

Automate a form filling workflow:
  • Python
  • JavaScript
from hopx_ai import Sandbox

sandbox = Sandbox.create(template="desktop")

try:
    # Click on input field (assuming coordinates)
    sandbox.desktop.click(400, 300)
    
    # Type username
    sandbox.desktop.type("myusername")
    
    # Press Tab to move to next field
    sandbox.desktop.press("Tab")
    
    # Type password
    sandbox.desktop.type("mypassword")
    
    # Press Enter to submit
    sandbox.desktop.press("Return")
    
finally:
    sandbox.kill()

Common Shortcuts

Common keyboard shortcuts for automation:
  • Copy: Ctrl+C (or Cmd+C on macOS)
  • Paste: Ctrl+V (or Cmd+V on macOS)
  • Cut: Ctrl+X (or Cmd+X on macOS)
  • Select All: Ctrl+A (or Cmd+A on macOS)
  • Undo: Ctrl+Z (or Cmd+Z on macOS)
  • Redo: Ctrl+Y (or Cmd+Shift+Z on macOS)
  • Save: Ctrl+S (or Cmd+S on macOS)
  • Close Tab: Ctrl+W (or Cmd+W on macOS)
  • New Tab: Ctrl+T (or Cmd+T on macOS)

Next Steps