adb 模擬按鍵輸入的命令主要經過 input 進行html
Usage: input [<source>] <command> [<arg>...]
The sources are: mouse keyboard joystick touchnavigation touchpad trackball stylus dpad gesture touchscreen gamepad 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)
經常使用命令android
物理鍵:git
adb shell input keyevent 26 # 電源鍵 adb shell input keyevent 82 # 菜單鍵 adb shell input keyevent 3 # HOME 鍵 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 # 暫停播放
能夠經過上 模擬電源鍵 來切換點亮和熄滅屏幕,但若是明確地想要點亮或者熄滅屏幕,那可使用以下方法。ide
adb shell input keyevent 224 # 點亮屏幕 adb shell input keyevent 223 # 熄滅屏幕
觸擊屏幕post
adb shell input tap <X> <Y> # x,y爲座標位置
划動屏幕用到了 swipe 命令,它有四個參數,分別是起始點x座標 起始點y座標 結束點x座標 結束點y座標。spa
若是鎖屏沒有密碼,是經過滑動手勢解鎖,那麼能夠經過 input swipe 來解鎖。3d
# 四個參數:起始點x座標 起始點y座標 結束點x座標 結束點y座標。 adb shell input swipe 300 1000 300 500 # 向上滑動 adb shell input swipe 300 100 300 1000 # 向下滑動 adb shell input swipe 1000 500 200 500 # 向左滑動 adb shell input swipe 200 500 1000 500 # 向右滑動
在焦點處於某文本框時,能夠經過 input 命令來輸入文本。
adb shell input text hello # 輸入hello
官方文檔地址:https://developer.android.com/reference/android/view/KeyEvent
中文keycode大全:adb——keyevent命令大全