Automated UI testing, continuous integration builds, and interactive device debugging frequently require triggering touch coordinates, gestures, and keystrokes on connected Android devices without manual user interaction. The Android Debug Bridge (ADB) shell includes a built-in event injection binary named input. Operating directly above the Linux kernel input subsystem, adb shell input simulates physical taps, multi-second swipes, text entry, and hardware button presses across any Android phone, tablet, or emulator.
Prerequisites and Coordinate Discovery
Ensure that USB Debugging is enabled on the device and that your computer detects the connection via adb devices.
Because tap and swipe events require precise pixel coordinates (X and Y positions), determine your device screen resolution using wm size:
adb shell wm size
To inspect exact touch coordinates in real time on the device screen:
- Open Settings > System > Developer Options on your Android device.
- Locate the Input section.
- Toggle on Pointer Location.
When Pointer Location is active, tapping or dragging across the screen displays an overlay banner at the top showing the exact X and Y pixel coordinates of your finger touch.
Simulating Single Taps and Coordinates
The tap command simulates a capacitive touch at specified X and Y pixel coordinates. The syntax requires passing the X coordinate followed by the Y coordinate:
adb shell input tap <X> <Y>
For example, to tap a button located at horizontal position 540 and vertical position 1200 on a 1080×2400 display:
adb shell input tap 540 1200
To tap the app drawer or launcher search bar near the top of the home screen:
adb shell input tap 540 250
Simulating Swipes, Scrolls, and Long Presses
The swipe command simulates a drag from starting coordinates (X1, Y1) to destination coordinates (X2, Y2). An optional duration parameter (in milliseconds) determines the gesture speed.
adb shell input swipe <X1> <Y1> <X2> <Y2> [duration_ms]
To simulate a quick swipe down to expand the Quick Settings notification shade:
adb shell input swipe 540 50 540 1200 300
To simulate scrolling down a web page or social media feed (swiping upward from bottom to top):
adb shell input swipe 540 1600 540 400 400
To execute a long-press (such as holding down an app icon to open its contextual menu), specify identical start and end coordinates with an extended duration (e.g., 1500 ms):
adb shell input swipe 540 1200 540 1200 1500
Simulating Drag and Drop Gestures
On newer Android releases (Android 10 and later), the draganddrop command moves items smoothly between coordinates without triggering fling velocity calculations:
adb shell input draganddrop 300 600 800 600 1000
Typing Text and Handling Special Characters
The text command simulates typing alphanumeric strings into the currently focused text field:
adb shell input text "HelloWorld"
Because the shell interprets spaces and shell meta-characters, spaces must be represented using %s or escaped with quotation marks:
adb shell input text "Automated%sTesting%sInput"
To input special characters or email addresses:
adb shell input text "user\\@example.com"
Simulating Hardware Buttons and Keyevents
The keyevent command triggers Android key codes corresponding to hardware buttons, navigation controls, and keyboard keys. Common Android key codes include:
3: HOME key4: BACK key24: VOLUME_UP25: VOLUME_DOWN26: POWER button (wakes or sleeps the device)66: ENTER key67: DEL (Backspace)187: APP_SWITCH (Recent Apps Overview)
To return to the home screen:
adb shell input keyevent 3
To open the Recent Apps overview:
adb shell input keyevent 187
To wake up a sleeping screen:
adb shell input keyevent 26
To submit a form by pressing Enter:
adb shell input keyevent 66
Building Shell Automation Scripts
Combining these commands inside shell scripts allows chaining complex workflows. For example, to unlock a simple numerical PIN (e.g., PIN: 1234):
# Wake device
adb shell input keyevent 26
# Swipe up to show lock screen keypad
adb shell input swipe 540 1800 540 600 300
# Pause 1 second for animation
sleep 1
# Input PIN numbers and press Enter
adb shell input text "1234"
adb shell input keyevent 66
Automating input commands via ADB provides a lightweight, dependency-free mechanism to drive Android interfaces for testing, kiosk management, and device recovery.