Documentation Index
Fetch the complete documentation index at: https://docs.hopx.ai/llms.txt
Use this file to discover all available pages before exploring further.
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:
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)
import { Sandbox } from '@hopx-ai/sdk';
const sandbox = await Sandbox.create({ template: 'desktop' });
// Type text
await sandbox.desktop.keyboardType('Hello, World!');
Pressing Keys
Press individual keys:
# 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")
// Press Enter
await sandbox.desktop.keyboardPress('Return');
// Press Escape
await sandbox.desktop.keyboardPress('Escape');
// Press Tab
await sandbox.desktop.keyboardPress('Tab');
Key Combinations
Execute key combinations (modifier keys + main key):
# 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')
// Ctrl+C (copy)
await sandbox.desktop.keyboardCombination(['ctrl', 'c']);
// Ctrl+V (paste)
await sandbox.desktop.keyboardCombination(['ctrl', 'v']);
// Ctrl+Shift+T (new tab)
await sandbox.desktop.keyboardCombination(['ctrl', 'shift', 't']);
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:
# 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)
// Note: JavaScript SDK may have different delay parameter
await sandbox.desktop.keyboardType('Text to type');
Complete Example
Automate a form filling workflow:
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()
import { Sandbox } from '@hopx-ai/sdk';
const sandbox = await Sandbox.create({ template: 'desktop' });
try {
// Click on input field (assuming coordinates)
await sandbox.desktop.mouseClick(400, 300);
// Type username
await sandbox.desktop.keyboardType('myusername');
// Press Tab to move to next field
await sandbox.desktop.keyboardPress('Tab');
// Type password
await sandbox.desktop.keyboardType('mypassword');
// Press Enter to submit
await sandbox.desktop.keyboardPress('Return');
} finally {
await 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