直接从计算机在 Android 设备上打字?
您可以使用 ADB 直接从计算机在 Android 设备上打字吗?如果是这样,怎么办?
Can you use ADB to type directly on an android device from a computer? If so, how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
虽然这个问题相当老了,但我想添加这个答案:
您可以使用
adb shell input keyevent KEYCODE
分别。adb shell 输入文本“mytext”
。所有键码的列表可以在此处找到Although this question is rather old, I'd like to add this answer:
You may use
adb shell input keyevent KEYCODE
resp.adb shell input text "mytext"
. A list of all keycodes can be found here正如Manuel所说,您可以使用
adb shell输入文本
,但需要将空格替换为%s
,并处理引号。这是一个简单的 bash 脚本,可以让这一切变得非常简单:另存为,例如,atext 并使其可执行。然后您可以调用不带引号的脚本...
...除非您需要发送引号,在这种情况下您确实需要将它们放在其他类型的引号之间(这是 shell 限制):
As Manuel said, you can use
adb shell input text
, but you need to replace spaces with%s
, as well as handle quotes. Here's a simple bash script to make that very easy:Save as, say,
atext
and make executable. Then you can invoke the script without quotes......unless you need to send quotes, in which case you do need to put them between the other type of quotes (this is a shell limitation):
为了避免扩展/评估文本参数(即对于“$”或“;”等特殊字符),您可以将它们括在引号中,如下所示:
To avoid expansion/evaluation of the text parameter (i.e. for special characters like '$' or ';'), you could wrap them into quotes like this:
这是一个基于 Bash 的解决方案,适用于任意/复杂字符串(例如随机密码)。这里提出的其他解决方案在这方面对我来说都失败了:
以下代码可用于重复/连续输入:
Here is a
Bash
-based solution that works for arbitrary/complex strings (e.g. random passwords). The other solutions presented here all failed for me in that regard:The following code may be used for repeated/continuous input:
input
不支持 UTF-8 或其他编码,如果您尝试的话,您会看到类似的内容,因此,如果这些是您的意图,您需要更强大的东西。
以下脚本使用 AndroidViewClient/culebra 和 CulebraTester2-public 后端以避免
输入
限制。input
does not support UTF-8 or other encodings, you will see something like this if you try ittherefore if these are your intention you need something more robust.
The following script uses AndroidViewClient/culebra with CulebraTester2-public backend to avoid
input
limitations.it finds an
EditText
and then enters some Chinese characters and a emoji.You can achieve the same using
bash
andcurl
if entering text is the only you need.当使用 zsh 时,这里有一个更强大的函数来向 Android 提供文本:
虽然 Zsh 引用可能与常规 POSIX shell 略有不同,但我没有发现任何它不起作用的地方。丹的答案缺失,例如
>
也需要转义。我将它与
pass show ... | 一起使用adbtext
。When using zsh, here is a more robust function to feed text to Android:
While Zsh quoting may be slightly different from a regular POSIX shell, I didn't find anything it wouldn't work on. Dan's answer is missing for example
>
which also needs to be escaped.I am using it with
pass show ... | adbtext
.