当前位置:   article > 正文

[7] ADB 模拟按键/输入_adb 按键

adb 按键

adb shell里有个很实用的命令叫input,通过它可以做一些有趣的事情。
比如使用adb shell input keyevent <keycode>命令,不同的 keycode 能实现不同的功能,完整的 keycode ,部分如下:

keycode含义
3HOME 键
4返回键
5打开拨号应用
6挂断电话
24增加音量
25降低音量
26电源键
27拍照(需要在相机应用里)
64打开浏览器
66回车
82菜单键
85播放/暂停
86停止播放
87播放下一首
88播放上一首
122移动光标到行首或列表顶部
123移动光标到行末或列表底部
126恢复播放
127暂停播放
164静音
176打开系统设置
187切换应用
207打开联系人
208打开日历
209打开音乐
210打开计算器
220降低屏幕亮度
221提高屏幕亮度
223系统休眠
224点亮屏幕
231打开语音助手
276如果没有 wakelock 则让系统休眠

电源键

adb shell input keyevent 26
  • 1

菜单键

adb shell input keyevent 82
  • 1

HOME 键

adb shell input keyevent 3
  • 1

返回键

adb shell input keyevent 4
  • 1

音量控制

增加音量:

adb shell input keyevent 24
  • 1

降低音量:

adb shell input keyevent 25
  • 1

静音:

adb shell input keyevent 164
  • 1

媒体控制

播放/暂停:

adb shell input keyevent 85
  • 1

停止播放:

adb shell input keyevent 86
  • 1

播放下一首:

adb shell input keyevent 87
  • 1

播放上一首:

adb shell input keyevent 88
  • 1

恢复播放:

adb shell input keyevent 126
  • 1

暂停播放:

adb shell input keyevent 127
  • 1

点亮/熄灭屏幕

点亮屏幕:

adb shell input keyevent 224
  • 1

熄灭屏幕:

adb shell input keyevent 223
  • 1

滑动解锁

如果锁屏没有密码,是通过滑动手势解锁,那么可以通过 input swipe 来解锁。
命令(参数以机型 Nexus 5,向上滑动手势解锁举例):

adb shell input swipe 300 1000 300 500
  • 1

参数 300 1000 300 500分别表示起始点x坐标起始点y坐标结束点x坐标结束点y坐标

点击

adb shell input tap 50 250
  • 1

参数50 250 是x,y轴的坐标。

输入文本

在焦点处于某文本框时,可以通过 input 命令来输入文本。

命令:

adb shell input text hello
  • 1

现在 hello 出现在文本框了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/56436
推荐阅读
相关标签
  

闽ICP备14008679号