monkeyrunner
from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage
device = MonkeyRunner.waitForConnection()
monkeyrunner –v INFO + 脚本路径

adb shell getevent

device.wake( ) 点亮屏幕

device.type('10086') 输入10086

MonkeyRunner.sleep(3) 等待3s

device.drag((236,440),(236,300),2,10) 滑屏:起点坐标(236,440),终点坐标(236,300)

device.drag((236,440),(236,440),2,10) 长按

device.touch(170,524,'DOWN_AND_UP') 点击屏幕某处,坐标值为(170,254)

device.press('KEYCODE_VOLUME_UP','DOWN_AND_UP') 增大音量

device.press('KEYCODE_VOLUME_DOWN','DOWN_AND_UP') 减少音量

device.press('KEYCODE_HOME','DOWN_AND_UP') 返回主界面

device.press('KEYCODE_BACK','DOWN_AND_UP') 返回上一级菜单

device.press('KEYCODE_MENU','DOWN_AND_UP') 进入菜单页

device.press('KEYCODE_CALL','DOWN_AND_UP') 进入拨号页或点按拨号键

device.press('KEYCODE_DPAD_UP','DOWN_AND_UP') 向上移动光标

device.press('KEYCODE_DPAD_DOWN','DOWN_AND_UP') 向下移动光标

device.press('KEYCODE_DPAD_LEFT','DOWN_AND_UP') 向左移动光标

device.press('KEYCODE_DPAD_RIGHT','DOWN_AND_UP') 向右移动光标

录制脚本代码
from com.android.monkeyrunner import MonkeyRunner as mr
from com.android.monkeyrunner.recorder import MonkeyRecorder as recorder

device = mr.waitForConnection()
recorder.start(device)

相应的按键对应的名称如下:
menu键:KEYCODE_MENU
home键:KEYCODE_HOME
back键:KEYCODE_BACK
search键:KEYCODE_SEARCH
call键:KEYCODE_CALL
end键:KEYCODE_ENDCALL
上导航键:KEYCODE_DPAD_UP
下导航键:KEYCODE_DPAD_DOWN
左导航键:KEYCODE_DPAD_LEFT
右导航键:KEYCODE_DPAD_RIGHT
ok键:KEYCODE_DPAD_CENTER
上音量键:KEYCODE_VOLUME_UP
下音量键:KEYCODE_VOLUME_DOWN
power键:KEYCODE_POWER
camera键:KEYCODE_CAMERA

05-11 22:03