adb shell输入带空格的文本

kzipqqlq  于 12个月前  发布在  Shell
关注(0)|答案(6)|浏览(245)

如何使用adb shell input text发送带有空格的文本,如**“some text”**?
发现以下解决方案
adb shell input text "some%stext"工作正常。但是有没有简单的方法用%s替换空格?

示例:

$ 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)
tvmytwxo

tvmytwxo1#

你可以用\<space>来做,像这样:

adb shell input text "some\ text"
pdtvr36n

pdtvr36n2#

安装了gnu-linux sed(或其他)(大多数linux机器都预装了它)-你可以使用sed来用%s替换空格。

adb shell input text $(echo "some text with spaces" | sed 's/ /\%s/g')

%符号必须用\转义。

nwo49xxi

nwo49xxi3#

你可以发送你的文本像:

Text = "some text with spaces"

将空白替换为%s

adb shell input text some%stext%swith%sspaces
798qvoo8

798qvoo84#

adb shell“input text 'some text'”

vvppvyoh

vvppvyoh5#

替换特殊字符的最佳方法是。

val message = text.replace("|", "\\|")
            .replace("\"", "\\\"")
            .replace("\'", "\\\'")
            .replace("<", "\\<")
            .replace(">", "\\>")
            .replace(";", "\\;")
            .replace("?", "\\?")
            .replace("`", "\\`")
            .replace("&", "\\&")
            .replace("*", "\\*")
            .replace("(", "\\(")
            .replace(")", "\\)")
            .replace("~", "\\~")
            .replace(" ", "\\ ")
3lxsmp7m

3lxsmp7m6#

用单引号括起全文:

adb shell input text 'some text'

相关问题