adb shell input text with space

99封情书 提交于 2019-12-10 09:47:18

问题


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)

回答1:


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

adb shell input text "some\ text"



回答2:


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




回答3:


You can send your text like:

Text = "some text with spaces"

Replace blanks with %s:

adb shell input text some%stext%swith%sspaces


来源:https://stackoverflow.com/questions/45041320/adb-shell-input-text-with-space

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!