ByteScope

input text

changes the device

Types a string into whatever field currently has focus.

Command
adb shell input text
Commands
Input and touch
Risk
changes the device

Syntax

input text <string>

Examples

  • input text 'hello world'

    Quote it. Inside single quotes the shell leaves every character alone.

  • input text 'user@example.com'

    Filling a login field from a real keyboard instead of a phone one.

  • input keyevent 66

    Press Enter afterwards, since `input text` types no newline.

Reading the output

Nothing. The characters appear on the phone, or they do not — there is no report either way, so watch the screen.

Output fields

FieldMeaning
(no output)The command ran. Whether the text arrived is only visible on the phone.

What access it needs

Nothing beyond an authorised `adb` connection — no root, no `adb root`, no `su`, and nothing to switch on in developer options besides USB debugging itself. `input` is a one-line shell script that runs `cmd input "$@"` (AOSP `cmds/input/input.sh`), so the characters are injected with the identity of the `shell` user, and the platform permission standing behind that is `android.permission.INJECT_EVENTS`, which `com.android.shell` is granted in its own manifest. What the grant deliberately does not include is any way to aim. `runText` accepts an input source, an optional `-d <displayId>` and the string, and nothing else — there is no argument naming a target app, activity or field — so the characters land wherever focus happens to be on that display at the instant they arrive. Pacing and ordering therefore matter far more in a script than access does: a dialog that appeared while you were not looking is a perfectly authorised place for your password to be typed. And there is no acknowledgement to wait on. `sendText` hands each event to the injector and never inspects a result, so the command exits without knowing whether anything downstream consumed a single keystroke; a `screencap` is the only honest confirmation.

Failure messages, decoded

MessageMeaning
java.lang.IllegalArgumentException: Argument expected after "text"`runText` asks for a required argument and there was none, so `input text` with nothing after it throws. The line arrives under an `Exception occurred while executing 'text':` banner with a stack trace, all on stderr. Note what it is *not*: an empty string. `input text ''` is a legal, quoted, empty argument and does nothing quietly.
Exception occurred while executing 'text':The shell-command handler caught a `Throwable`; the line after the banner names it. The non-ASCII case ends here: `KeyCharacterMap.getEvents` is documented to return null when the character array cannot be generated by the current key character map, and the source read for this page walks `events.length` with no null check, so a string containing `é` or `日本語` throws a `NullPointerException` rather than typing part of it. Older builds are reported to fail more quietly — see the note below — which is exactly why this page refuses non-ASCII up front instead of trying.
Error: Invalid arguments for display ID.`-d` was given something that is not an integer and not `DEFAULT_DISPLAY` or `INVALID_DISPLAY`. It is thrown while parsing, before any character is sent, so nothing was typed. Look at the token after `-d`, not at your string.
cmd: Can't find service: input`cmd` could not find the `input` service to hand the subcommand to, because `input.sh` is only a wrapper around `cmd input`. Expected while the device is still booting, before `system_server` has published it — the same shape of failure the `settings` and `window` services give at the same moment.

What it changes, and the way back

Nothing on the device is deleted, but the characters go to whatever has focus at that moment: a chat message, a search box, a login or password field, or a confirmation dialog that appeared since you last looked. Nothing takes them back once something submits them. If nothing has, `input keyevent 67` (Delete) removes them one character at a time, and it is `input keyevent 66` (Enter) that submits a form. Look at the screen before you type, and never send a secret you would not be willing to see left in that field.

Version and vendor notes

  • ASCII only, and this is a limit of the platform command rather than of the cable or the shell: `input text` ends in a virtual-keyboard character map that has keys only for printable ASCII, so Japanese, Chinese and accented letters produce no key events at all. A desktop adb cannot type them either.
  • `%s` inside the argument is turned into a space by `input` itself, before the keyboard ever sees it — and there is no escape for it, because `%%s` becomes a percent sign and a space. Split the string so that `%` and `s` are never adjacent in one invocation.
  • Single quotes cannot carry an apostrophe. Break the string there and send the apostrophe as `input keyevent 75`; the `'\''` escaping dance is the kind of thing that gets copied wrong.
  • A space needs no `%s` when the argument is quoted: the shell keeps it inside the one word and the keyboard maps it to the space key.

We have a UI for this

Android ADB Toolbox runs this command over USB and parses what comes back — a Chromium browser, no SDK, nothing uploaded.

Open Android ADB Toolbox

Related commands

Commands that turn up in the same session as input text.

CommandWhat it does
input keyeventPresses a hardware or virtual key — Home, Back, Power, volume, Enter.
geteventStreams raw input events straight from the kernel, or lists what each input device can report.
am startStarts an activity by component or by intent — the fastest way to test whether a deep link resolves.

Running these commands, when they need root, why output differs between phones and running them from a browser are covered once in the adb shell command reference.