Skip to main content
Glama
rahulkr
by rahulkr

press_key

Simulate key presses on Android devices using keycodes like HOME, BACK, VOLUME_UP, or ENTER for automated testing and device control.

Instructions

Press a key by keycode name or number.

Common keycodes:
- HOME (3), BACK (4), CALL (5), ENDCALL (6)
- VOLUME_UP (24), VOLUME_DOWN (25), POWER (26)
- CAMERA (27), ENTER (66), DEL/BACKSPACE (67)
- TAB (61), SPACE (62), MENU (82)
- SEARCH (84), MEDIA_PLAY_PAUSE (85)
- PAGE_UP (92), PAGE_DOWN (93)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keycodeYes
device_serialNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The press_key tool handler function that maps common key names to keycodes and sends the corresponding ADB input keyevent command to the device.
    @mcp.tool()
    def press_key(keycode: str, device_serial: str | None = None) -> str:
        """
        Press a key by keycode name or number.
        
        Common keycodes:
        - HOME (3), BACK (4), CALL (5), ENDCALL (6)
        - VOLUME_UP (24), VOLUME_DOWN (25), POWER (26)
        - CAMERA (27), ENTER (66), DEL/BACKSPACE (67)
        - TAB (61), SPACE (62), MENU (82)
        - SEARCH (84), MEDIA_PLAY_PAUSE (85)
        - PAGE_UP (92), PAGE_DOWN (93)
        """
        # Handle common names
        key_map = {
            'HOME': '3', 'BACK': '4', 'ENTER': '66', 'DELETE': '67', 'DEL': '67',
            'TAB': '61', 'SPACE': '62', 'MENU': '82', 'SEARCH': '84',
            'VOLUME_UP': '24', 'VOLUME_DOWN': '25', 'POWER': '26',
            'PAGE_UP': '92', 'PAGE_DOWN': '93', 'ESCAPE': '111', 'ESC': '111'
        }
        
        key = key_map.get(keycode.upper(), keycode)
        return run_adb(["shell", "input", "keyevent", key], device_serial)
  • The @mcp.tool() decorator registers the press_key function as an MCP tool.
    @mcp.tool()
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It describes what the tool does (press a key) but lacks critical behavioral details: it doesn't specify which device or context this applies to (e.g., Android device control), whether it requires specific permissions, potential side effects, or error handling. The keycode list adds some context but doesn't cover behavioral traits adequately for a tool with no annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded: the first sentence clearly states the purpose, followed by a useful list of keycodes. Every sentence earns its place, with no redundant information. However, the list formatting could be slightly more structured for readability, but it remains efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (a key-pressing tool with 2 parameters, no annotations, and an output schema), the description is partially complete. It explains the keycode parameter well but lacks context on device targeting (via 'device_serial'), behavioral aspects, and integration with sibling tools. The presence of an output schema means return values don't need explanation, but other gaps remain, making it adequate but with clear room for improvement.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds significant meaning beyond the input schema. The schema has 0% description coverage and only lists 'keycode' and 'device_serial' as parameters. The description explains that 'keycode' can be a name or number and provides a comprehensive list of common keycodes with mappings, which clarifies the parameter's expected values and usage. This compensates well for the low schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Press a key by keycode name or number.' It specifies the verb ('press') and resource ('key'), making it understandable. However, it doesn't explicitly differentiate from sibling tools like 'press_back' or 'press_home', which are more specific versions of this general key-pressing functionality.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'press_back' or 'press_home' that handle specific keys, nor does it explain when to use keycodes versus those dedicated tools. Usage context is implied through the keycode list but not explicitly stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rahulkr/r_adb_mcp_server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server