參考:
Android模擬點選的四種方式
https://blog.csdn.net/eclipsexys/article/details/38661237
ADB控制模擬操作
ADB中透過input來實現,用於輸入 touch,key等事件:
The sources are:
- trackball
- joystick
- touchnavigation
- mouse
- keyboard
- gamepad
- touchpad
- dpad
- stylus
- touchscreen
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)
透過使用sendevent
adb提供了控制手機的另一種實現: sendevent [device] [type] [code] [value]
eg:229就是menu的type值
sendevent /dev/input/event0 1 229 1 sendevent /dev/input/event0 1 229 0
這兩句需要一起執行,因為一個點選事件包含down和up,不然不能執行操作。