# Start of Script type= user count= 49 speed= 1.0 start data >> LaunchActivity(com.mpowerlabs.coin.android, com.mpowerlabs.coin.android.LoginActivity) # 3120021258 DispatchPress(KEYCODE_3) UserWait(200) DispatchPress(KEYCODE_1) UserWait(200) DispatchPress(KEYCODE_3) UserWait(200) DispatchPress(KEYCODE_5) UserWait(200) DispatchPress(KEYCODE_0) UserWait(200) DispatchPress(KEYCODE_2) UserWait(200) DispatchPress(KEYCODE_1) UserWait(200) DispatchPress(KEYCODE_2) UserWait(200) DispatchPress(KEYCODE_5) UserWait(200) DispatchPress(KEYCODE_8) UserWait(200) # Pin 12345 DispatchPress(KEYCODE_DPAD_DOWN) UserWait(250) DispatchPress(KEYCODE_1) UserWait(200) DispatchPress(KEYCODE_2) UserWait(200) DispatchPress(KEYCODE_3) UserWait(200) DispatchPress(KEYCODE_4) UserWait(200) DispatchPress(KEYCODE_5) UserWait(200) # Down and enter DispatchPress(KEYCODE_DPAD_DOWN) UserWait(250) DispatchPress(KEYCODE_ENTER)
用法:adb shell monkey -f <script file> <运行脚本的次数>
例如,我们放一个脚本到 /sdcard/monkey.script,然后运行:
adb shell monkey -f /sdcard/monkey.script 10,那么这个脚本里面指定的动作就会被执行10次。
整理的脚本函数列表:
DispatchPointer(long downTime, long eventTime, int action, float x, float y, float pressure, float size, int metaState, float xPrecision, float yPrecision, int device, int edgeFlags) DispatchTrackball(long downTime, long eventTime, int action, float x, float y, float pressure, float size, int metaState, float xPrecision, float yPrecision, int device, int edgeFlags) DispatchKey(long downTime, long eventTime, int action, int code, int repeat, int metaState, int device, int scancode) DispatchFlip(boolean keyboardOpen) DispatchPress(int keyCode) LaunchActivity(String pkg_name, String cl_name) UserWait(long sleeptime) LongPress()
键值列表参见 。