mobile_key_press
Press physical or virtual buttons on Android devices to navigate interfaces, return to home screens, access recent apps, or confirm actions during mobile automation tasks.
Instructions
Press a physical or virtual button on the Android device.
Args: button: Button name (BACK, HOME, RECENT, ENTER)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| button | Yes |
Input Schema (JSON Schema)
{
"properties": {
"button": {
"type": "string"
}
},
"required": [
"button"
],
"type": "object"
}
Implementation Reference
- main.py:164-186 (handler)Implementation of the mobile_key_press tool handler. Maps button names to keys and presses them using the uiautomator2 device.press method. Includes error handling and device check.@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)}"