使用adb命令模拟按键 *** 作,主要是找到对应的按键的keycode,主要命令adb shell input keyevent
KeyCode对应查找:
frameworks/base/core/res/res/values/attrs.xml
frameworks/base/core/java/android/view/KeyEvent.java
常用按键
#主页键
KEYCODE_HOME = 3
#返回键
KEYCODE_BACK = 4
#电源键
KEYCODE_POWER = 26
#菜单键
KEYCODE_MENU = 82
#多任务键
KEYCODE_APP_SWITCH = 187
adb模拟示例
# 模拟文本输入 *** 作:模拟输入abc
adb shell input text abc
#通过键值模拟按键 *** 作:模拟按back键
adb shell input keyevent 4
或 adb shell input keyevent KEYCODE_BACK
#通过坐标模拟点击 *** 作:点击横坐标300纵坐标500的点
adb shell input tap 300 500
#通过坐标模拟滑动 *** 作:从(200,300)的点划到(500,300)的点,滑动时间100ms
adb shell input swipe 200 300 500 300 100
#通过坐标模拟拖动 *** 作:从(100,1220)的点拖动到(500,620)的点,滑动时间2000ms
adb shell input draganddrop 100 1220 500 620 2000
#通过坐标模拟长按 *** 作:从(200,300)的点划到(201,301)的点,滑动时间2000ms,由于划动距离短,在一个图标之内则主观显示为长按 *** 作
adb shell input swipe 200 300 201 301 2000
#通过坐标/键值模拟同时按下两个键,用and连接:电源键亮屏并点击菜单
adb shell input keyevent KEYCODE_POWER and KEYCODE_MENU
获取按键keycode方法
C:\Users\Admin>adb shell
msm8953_64:/ $ getevent -l
add device 1: /dev/input/event5
name: "msm8953-sku3-snd-card Button Jack"
add device 2: /dev/input/event4
name: "msm8953-sku3-snd-card Headset Jack"
could not get driver version for /dev/input/mouse0, Not a typewriter
add device 3: /dev/input/event2
name: "hbtp_vm"
add device 4: /dev/input/event1
name: "goodix-ts"
add device 5: /dev/input/event0
name: "qpnp_pon"
could not get driver version for /dev/input/mice, Not a typewriter
add device 6: /dev/input/event3
name: "gpio-keys"
/dev/input/event0: EV_KEY KEY_POWER DOWN
/dev/input/event0: EV_SYN SYN_REPORT 00000000
/dev/input/event0: EV_KEY KEY_POWER UP
/dev/input/event0: EV_SYN SYN_REPORT 00000000
根据输出KEY_POWER,可以在frameworks/base/core/res/res/values/attrs.xml
找到对应的KEYCODE_POWER
https://blog.csdn.net/guo_899/article/details/84978661
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)