Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adb shell input text with space

Tags:

android

shell

adb

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)
like image 717
Lava Sangeetham Avatar asked Jul 11 '17 17:07

Lava Sangeetham


People also ask

How to use keyevent in ADB shell?

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:

How to send embedded spaces with the input command?

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?

How do I send an event to a device using adb shell?

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.

What is the difference between sendevent and ADB input?

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


3 Answers

You can do it with \<space>, like this:

adb shell input text "some\ text"
like image 110
KS Ravikumar Avatar answered Oct 17 '22 05:10

KS Ravikumar


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 \.

like image 40
kai-dj Avatar answered Oct 17 '22 05:10

kai-dj


You can send your text like:

Text = "some text with spaces"

Replace blanks with %s

adb shell input text some%stext%swith%sspaces
like image 1
Ingo Avatar answered Oct 17 '22 05:10

Ingo