ADB Shell 输入事件
adb shell input keyevent
和 adb shell sendevent
之间的基本区别是什么?我应该使用哪一个来输入字符?我们传递给这两个命令的键码是否相同?
What is the basic difference between adb shell input keyevent
and adb shell sendevent
? Which one should I use for inputting a character? Are the keycodes the same that we pass to both the commands?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
通过
adb shell input keyevent
,event_code
或string
将被发送到设备。event_code
的一些可能值包括:sendevent
实用程序发送触摸或键盘事件,以及用于模拟硬件事件的其他事件。有关详细信息,请参阅本文: Android,低级 shell 点击屏幕。By
adb shell input keyevent
, either anevent_code
or astring
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.更新:
使用
adb shell 输入
:..
..
..
..
..
Updating:
Using
adb shell input
:..
..
..
..
..
另外,如果您想使用输入命令发送嵌入的空格,请使用
%s
将产生
正在输入的示例。
%
本身不需要转义 - 只有特殊的%s
对才会被特殊处理。这当然会导致一个明显的问题,即如何输入文字字符串%s
,您必须使用两个单独的命令来完成此操作。Also, if you want to send embedded spaces with the input command, use
%s
will yield
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.我为 Windows 用户编写了一个简单的 Powershell 脚本,将按键映射到 adb shell 输入事件。并通过 LAN 远程控制 Android 设备。
不知道有没有人觉得有用,不过我还是分享一下。
I wrote a simple Powershell script for windows users to map keys to adb shell input events. And controll an Android device remotely over LAN.
I don't know if anyone finds it usefull, but I'll share it anyways.
另一个区别是:
可以在此处找到 AOSP 框架内部的更多详细代码跟踪:
http://www.srcmap.org/sd_share/4/aba57bc6/AOSP_adb_shell_input_Code_Trace.html#RefId=7c8f5285
One other difference:
More detail code trace into inside AOSP Framework can be found here:
http://www.srcmap.org/sd_share/4/aba57bc6/AOSP_adb_shell_input_Code_Trace.html#RefId=7c8f5285
顺便说一句,如果您试图找到一种将双引号发送到设备的方法,请尝试以下操作:
我不确定为什么没有引号的事件代码,但这个解决方法可以完成这项工作。另外,如果您使用 MonkeyDevice (或 ChimpChat),您应该在调用 MonkeyDevice.type 之前测试每个字符,否则当你尝试发送时你什么也得不到”
By the way, if you are trying to find a way to send double quotes to the device, try the following:
I'm not sure why there's no event code for quotes, but this workaround does the job. Also, if you're using MonkeyDevice (or ChimpChat) you should test each caracter before invoking monkeyDevice.type, otherwise you get nothing when you try to send "
如果您想在多个设备连接时向特定设备发送文本。首先使用 adb devices 查找连接的设备,
然后获取您的特定设备 ID 并尝试以下操作
If you want to send a text to specific device when multiple devices connected. First look for the attached devices using adb devices
then get your specific device id and try the following
参考号仓库:ADB Automate Android 手机
Ref. repo: ADB Automate Android Phone
向在 Android 设备中运行的 React-Native 应用发送重新加载调用:
adb shell 输入键盘文本“rr”
To send a reload call to a React-Native app running in a android device:
adb shell input keyboard text "rr"