mobile_key_press
Press physical or virtual buttons on Android devices to navigate interfaces, trigger actions, or control applications during automation tasks.
Instructions
Press a physical or virtual button on the Android device.
Args: button: Button name (BACK, HOME, RECENT, ENTER)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| button | Yes |
Implementation Reference
- main.py:164-186 (handler)The core handler function for the 'mobile_key_press' tool. It is decorated with @mcp.tool() for automatic registration in FastMCP. The function maps button names to uiautomator2 keys and presses the button on the connected Android device, with error handling for uninitialized device.@mcp.tool() def mobile_key_press(button: str) -> str: """Press a physical or virtual button on the Android device. Args: button: Button name (BACK, HOME, RECENT, ENTER) """ if device is None: return "Error: Device not initialized. Please call mobile_init() first to establish connection with Android device." button_map = { "BACK": "back", "HOME": "home", "RECENT": "recent", "ENTER": "enter" } key = button_map.get(button.upper(), button.lower()) try: device.press(key) return f"Successfully pressed {button} button" except Exception as e: return f"Error pressing {button} button: {str(e)}"