How to send text with spaces like "some text" using adb shell input text
?
Found following solution
adb shell input text "some%stext"
is working fine. But any easy way to replace space with %s?
Example:
$ adb shell input text "some text"
Error: Invalid arguments for command: text
Usage: input [<source>] <command> [<arg>...]
The sources are:
keyboard
mouse
joystick
touchnavigation
touchpad
trackball
dpad
stylus
gamepad
touchscreen
The commands and default sources are:
text <string> (Default: touchscreen)
keyevent [--longpress] <key code number or name> ... (Default: keyboard)
tap <x> <y> (Default: touchscreen)
swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
press (Default: trackball)
roll <dx> <dy> (Default: trackball)
By adb shell input keyevent, either an event_code or a string will be sent to the device. usage: input [text|keyevent] input text <string> input keyevent <event_code> Some possible values for event_code are:
Also, if you want to send embedded spaces with the input command, use %s being input. % itself does not need escaping - only the special %s pair is treated specially. This leads of course to the obvious question of how to enter the literal string %s, which you would have to do with two separate commands. Any way to turn auto correct off here?
By adb shell input keyevent, either an event_code or a string will be sent to the device. Some possible values for event_code are: The sendevent utility sends touch or keyboard events, as well as other events for simulating the hardware events. Refer to this article for details: Android, low level shell click on screen.
so in nutshell sendevent is way faster than adb input! This answers the OP question; this is the direct answer to the question as it stands. If you want to send a text to specific device when multiple devices connected. First look for the attached devices using adb devices
You can do it with \<space>
, like this:
adb shell input text "some\ text"
With gnu-linux sed (or others) installed (most linux machines come with it preinstalled) - you could use sed to replace spaces with %s.
adb shell input text $(echo "some text with spaces" | sed 's/ /\%s/g')
the %-sign has to be escaped with \.
You can send your text like:
Text = "some text with spaces"
Replace blanks with %s
adb shell input text some%stext%swith%sspaces
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With