press_home
Press the home button on an Android device to return to the main screen or exit apps during development, testing, or debugging workflows.
Instructions
Press the home button
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device_serial | No |
Implementation Reference
- src/adb_mcp_server/server.py:547-550 (handler)The handler function decorated with @mcp.tool(), which registers and implements the press_home tool. It presses the Android home button by calling the press_key helper function with the 'HOME' keycode.@mcp.tool() def press_home(device_serial: str | None = None) -> str: """Press the home button""" return press_key("HOME", device_serial)
- src/adb_mcp_server/server.py:517-539 (helper)Supporting helper function (also exposed as tool) that maps human-readable key names like 'HOME' to ADB keycodes (e.g., '3') and executes the ADB shell input keyevent command via run_adb.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)
- src/adb_mcp_server/server.py:24-39 (helper)Core utility function used by press_key to execute ADB shell commands, handling device serial, timeouts, and error capture.def run_adb(args: list[str], device_serial: str | None = None, timeout: int = 30) -> str: """Run an ADB command and return output""" cmd = ["adb"] if device_serial: cmd.extend(["-s", device_serial]) cmd.extend(args) try: result = subprocess.run(cmd, capture_output=True, text=True, timeout=timeout) if result.returncode != 0 and result.stderr: return f"Error: {result.stderr}" return result.stdout except subprocess.TimeoutExpired: return "Error: Command timed out" except Exception as e: return f"Error: {str(e)}"