Input & Automation
Android 1.0+
Risk: SAFE
Send Hardware Keyevent / Button Press
Sends hardware keycodes such as Home, Back, Power, Volume Up/Down, Enter, or Camera.
Command Syntax
adb shell input keyevent
Generic Syntax:
input keyevent [--longpress] <KEYCODE>
Options & Parameters
| Flag | Description |
|---|---|
| 3 | KEYCODE_HOME |
| 4 | KEYCODE_BACK |
| 24 | KEYCODE_VOLUME_UP |
| 25 | KEYCODE_VOLUME_DOWN |
| 26 | KEYCODE_POWER |
| 66 | KEYCODE_ENTER |
| 82 | KEYCODE_MENU |
| 187 | KEYCODE_APP_SWITCH (Recents) |
| 224 | KEYCODE_WAKEUP (Turn screen on) |
| 223 | KEYCODE_SLEEP (Turn screen off) |
| --longpress | Simulate holding the key down. |
Real-World Usage Examples
Press HOME button (Keycode 3)
Returns to home screen.
adb shell input keyevent 3
Press BACK button (Keycode 4)
Navigates back.
adb shell input keyevent 4
Toggle POWER button / sleep / wake (Keycode 26)
Turns display on or off.
adb shell input keyevent 26
Take screenshot via hardware shortcut (Keycode 120 / SYSRQ)
Triggers hardware screenshot.
adb shell input keyevent 120