> ## 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.

# Keyboard Control

> Control keyboard input for sandbox desktop automation in HopX sandboxes. Send keyboard input, simulate key presses, type text, and handle keyboard shortcuts for desktop automation. Learn how to control keyboard interactions using Python and JavaScript SDKs or REST API. Includes examples for common keyboard operations.

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

<Note>
  Desktop automation requires a template with desktop support. Ensure your sandbox has desktop capabilities enabled.
</Note>

## Typing Text

Type text as if typed on a keyboard:

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    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)
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    import { Sandbox } from '@hopx-ai/sdk';

    const sandbox = await Sandbox.create({ template: 'desktop' });

    // Type text
    await sandbox.desktop.keyboardType('Hello, World!');
    ```
  </Tab>
</Tabs>

## Pressing Keys

Press individual keys:

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    # 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")
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    // Press Enter
    await sandbox.desktop.keyboardPress('Return');

    // Press Escape
    await sandbox.desktop.keyboardPress('Escape');

    // Press Tab
    await sandbox.desktop.keyboardPress('Tab');
    ```
  </Tab>
</Tabs>

## Key Combinations

Execute key combinations (modifier keys + main key):

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    # 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')
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    // 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']);
    ```
  </Tab>
</Tabs>

## 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:

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    # 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)
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    // Note: JavaScript SDK may have different delay parameter
    await sandbox.desktop.keyboardType('Text to type');
    ```
  </Tab>
</Tabs>

## Complete Example

Automate a form filling workflow:

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    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()
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    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();
    }
    ```
  </Tab>
</Tabs>

## 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)

## Related

* [Mouse Control](/core-concepts/desktop/mouse-control) - Control mouse input
* [CLI Reference](/cli/introduction) - Command-line interface for HopX
* [Clipboard](/core-concepts/desktop/clipboard) - Clipboard operations
* [X11 Advanced](/core-concepts/desktop/x11-advanced) - Advanced keyboard features
* **SDK**: [sandbox.desktop.type()](/sdk/python/desktop#type) - Python SDK method

## Next Steps

* Learn about [Mouse Control](/core-concepts/desktop/mouse-control) for clicking and dragging
* Explore [Clipboard](/core-concepts/desktop/clipboard) for copy/paste operations
* Review [VNC Server](/core-concepts/desktop/vnc-server) for remote desktop access
