press_button
Simulate a button press on a connected Android device to trigger actions like navigation, power, or volume control.
Instructions
Simulate a button press on the connected Android device using an Enum button
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| button | Yes |
Implementation Reference
- src/espresso_mcp/server.py:238-249 (handler)The main handler function for the 'press_button' tool. It is registered via @mcp.tool() decorator and simulates pressing an Android hardware button using ADB by sending a keyevent based on the Button enum value.@mcp.tool() def press_button(button: Button) -> str: """Simulate a button press on the connected Android device using an Enum button""" result = subprocess.run( ["adb", "shell", "input", "keyevent", button.value], capture_output=True, text=True, ) if result.returncode != 0: raise RuntimeError(f"Error pressing button '{button.name}': {result.stderr}") return f"Button '{button.name}' has been pressed."
- src/espresso_mcp/server.py:227-236 (schema)Enum type 'Button' used as input parameter for press_button tool, defining key codes for various Android buttons.class Button(Enum): HOME = "3" BACK = "4" MENU = "82" POWER = "26" VOLUME_UP = "24" VOLUME_DOWN = "25" CAMERA = "27" ENTER = "66"
- src/espresso_mcp/server.py:238-238 (registration)Registration of the press_button tool using the @mcp.tool() decorator.@mcp.tool()