[7] ADB 模拟按键/输入
生活随笔
收集整理的這篇文章主要介紹了
[7] ADB 模拟按键/输入
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
模擬按鍵/輸入
- 電源鍵
- 菜單鍵
- HOME 鍵
- 返回鍵
- 音量控制
- 媒體控制
- 點亮/熄滅屏幕
- 滑動解鎖
- 點擊
- 輸入文本
在 adb shell里有個很實用的命令叫input,通過它可以做一些有趣的事情。
比如使用adb shell input keyevent <keycode>命令,不同的 keycode 能實現不同的功能,完整的 keycode ,部分如下:
| 3 | HOME 鍵 |
| 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菜單鍵
adb shell input keyevent 82HOME 鍵
adb shell input keyevent 3返回鍵
adb shell input keyevent 4音量控制
增加音量:
adb shell input keyevent 24降低音量:
adb shell input keyevent 25靜音:
adb shell input keyevent 164媒體控制
播放/暫停:
adb shell input keyevent 85停止播放:
adb shell input keyevent 86播放下一首:
adb shell input keyevent 87播放上一首:
adb shell input keyevent 88恢復播放:
adb shell input keyevent 126暫停播放:
adb shell input keyevent 127點亮/熄滅屏幕
點亮屏幕:
adb shell input keyevent 224熄滅屏幕:
adb shell input keyevent 223滑動解鎖
如果鎖屏沒有密碼,是通過滑動手勢解鎖,那么可以通過 input swipe 來解鎖。
命令(參數以機型 Nexus 5,向上滑動手勢解鎖舉例):
參數 300 1000 300 500分別表示起始點x坐標、起始點y坐標、結束點x坐標、結束點y坐標。
點擊
adb shell input tap 50 250參數50 250 是x,y軸的坐標。
輸入文本
在焦點處于某文本框時,可以通過 input 命令來輸入文本。
命令:
adb shell input text hello現在 hello 出現在文本框了。
總結
以上是生活随笔為你收集整理的[7] ADB 模拟按键/输入的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ueditor 上传视频丢失src的解决
- 下一篇: [10] ADB 修改设置