当前位置:   article > 正文

Android系统adb模拟按键操作方法_adb 模拟按键

adb 模拟按键

使用adb命令模拟按键操作,主要是找到对应的按键的keycode,主要命令adb shell input keyevent <keycode>

KeyCode对应按键

KeyCode对应查找:
frameworks/base/core/res/res/values/attrs.xml <attr name="keycode">
frameworks/base/core/java/android/view/KeyEvent.java

常用按键

#主页键
KEYCODE_HOME = 3
#返回键
KEYCODE_BACK = 4
#电源键
KEYCODE_POWER = 26
#菜单键
KEYCODE_MENU = 82
#多任务键
KEYCODE_APP_SWITCH = 187
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
获取按键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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

根据输出KEY_POWER,可以在frameworks/base/core/res/res/values/attrs.xml找到对应的KEYCODE_POWER

相关参考

https://blog.csdn.net/guo_899/article/details/84978661

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

闽ICP备14008679号