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

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

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