ADB Shell Input Events
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
adb shell input lets you simulate taps, swipes, key presses, and text entry on an Android device from the command line. It is a practical tool for quick automation, debugging, kiosk setups, and reproducing UI flows without touching the screen manually.
The Most Common Commands
The input tool covers a few high-value event types directly.
Simulate a tap:
Simulate a swipe:
Simulate a key press:
The last example sends keycode 66, which is the Enter key.
Entering Text
You can also type text into the currently focused field.
Spaces are awkward because the shell and input tool both interpret them. A common trick is to use %s for a space.
This is useful for quick test data entry, though complex Unicode and punctuation input can still be finicky.
Useful Key Events
Some key events are especially common in Android testing.
These are handy when you need to automate navigation without a full UI testing framework.
Long Press and Drag
A long press can be approximated with a swipe whose start and end coordinates are the same but with a duration.
That presses at one location for roughly one second.
You can also use duration for controlled drags:
This is often enough for simple gesture automation.
Finding Coordinates
The weak point of raw input commands is that they need screen coordinates. A quick way to discover them is to enable Pointer Location in Android developer options or inspect the device resolution.
Knowing the device dimensions helps you choose stable tap and swipe positions.
Combining Input Commands
Simple automation often means chaining a few input commands together.
This is not a replacement for a full testing framework, but it is fast and effective for repeatable setup steps.
When input Is Not Enough
adb shell input works best for straightforward interactions. It becomes fragile when:
- the UI layout changes often
- animations affect timing
- elements move across devices and screen sizes
- accessibility text or view hierarchy matters more than raw coordinates
For those cases, higher-level tools such as UI Automator, Espresso, or Appium are usually better.
A Practical Debugging Use Case
Suppose a bug only appears after a specific navigation path. Raw ADB input commands can reproduce that path quickly in a shell script or terminal history, which makes manual debugging much easier than tapping through the same screens repeatedly.
That is one reason these commands stay useful even in teams that already use larger automation frameworks.
Common Pitfalls
The biggest pitfall is relying on hard-coded coordinates across devices with different screen sizes or densities. A tap that works on one phone may miss entirely on another.
Another issue is sending text before the target field has focus. adb shell input text writes to the active input target, not to a specific view by identifier.
Developers also expect perfect behavior for complex text, symbols, or international input. The input text command is convenient, but it is not a full keyboard emulator.
Finally, remember that command timing matters. If the UI has not finished transitioning, the next input event can hit the wrong screen.
Summary
- Use
adb shell inputto simulate taps, swipes, text entry, and key events. - '
tap,swipe,text, andkeyeventare the core commands to know.' - Use
%sfor spaces when sending text. - Raw coordinates are fast for debugging but fragile across device layouts.
- For stable UI automation, move to a higher-level Android testing tool when needed.

