http://blog.csdn.net/palmerma/article/details/8149093
• monkey.script
type= user
count= 20
speed= 1.0
start data >>
DispatchPress(KEYCODE_HOME)
DispatchPress(KEYCODE_MENU)
UserWait(2000)
LaunchActivity(com.android.settings, com.android.settings.Settings)
DispatchPress(KEYCODE_HOME)
• adb push monkey.script /mnt/sdcard
• adb shell monkey -f <script file> <times of running scripts>
Eg. adb shell monkey –f /mnt/sdcard/monkey.script 10
•DispatchPointer(long downTime, long eventTime, int action, loat 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)
•LaunchActivity(String pkg_name, String cl_name)
•DispatchPress(int keyCode)
•UserWait(long sleeptime)
•LongPress()
•captureDispatchPointer(downTime, eventTime, action, x, y, pressure, size, metaState, xPrecision, yPrecision, device, edgeFlags)
•captureDispatchKey(downTime, eventTime, action, code, repeat, metaState, device, scancode)
•captureDispatchFlip(boolean keyboardOpen)
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)
@downTime: at which this key code originally went down.
@eventTime: at which this event happened.
@action: ACTION_DOWN = 0, ACTION_UP=1, ACTION_MOVE=2
@x:
@y:
@pressure: The current pressure of this event. The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure), however values higher than 1 may be generated depending on the calibration of the input device.
@size: A scaled value of the approximate size of the area being pressed touched with the fin ger. The actual value in pixels corresponding to the finger touch is normalized wit h a device specific range of values and scaled to a value between 0 and 1.
@metaState: The state of any meta/modifier keys that were in effect when the event was generated.
@xPrecision
@yPrecision
@deivce: The id for the devices that this event came from. An id of zero indicates that the evet didn’t come from a physical device; other numbers are arbitrary and you shouldn’t depend on the values.
@edgeFlag: A bitfieldl indicating which edges, if any, where touched by this motion event.
Click Event
DispatchPointer(0, 0, 0, 200, 200, 0, 0, 0, 0, 0, 0, 0)
DispatchPointer(0, 0, 1, 200, 200, 0, 0, 0, 0, 0, 0, 0)
Drag Right
DispatchPointer(0, 0, 0, 300, 200, 0, 0, 0, 0, 0, 0, 0)
DispatchPointer(0, 0, 2, 200, 200, 0, 0, 0, 0, 0, 0, 0)
DispatchPointer(0, 0, 1, 100, 200, 0, 0, 0, 0, 0, 0, 0)
Drag Left
DispatchPointer(0, 0, 0, 100, 200, 0, 0, 0, 0, 0, 0, 0)
DispatchPointer(0, 0, 2, 200, 200, 0, 0, 0, 0, 0, 0, 0)
DispatchPointer(0, 0, 1, 300, 200, 0, 0, 0, 0, 0, 0, 0)
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)
@downTime: at which this key code originally went down.
@eventTime: at which this event happened.
@action: ACTION_DOWN=0,
@x:
@y: 2, move down 2 items; -2, move up 2 items.
@pressure: The current pressure of this event. The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure), however values higher than 1 may be generated depending on the calibration of the input device.
@size: A scaled value of the approximate size of the area being pressed touched with the fin ger. The actual value in pixels corresponding to the finger touch is normalized wit h a device specific range of values and scaled to a value between 0 and 1.
@metaState: The state of any meta/modifier keys that were in effect when the event was generated.
@xPrecision
@yPrecision
@deivce: The id for the devices that this event came from. An id of zero indicates that the evet didn’t come from a physical device; other numbers are arbitrary and you shouldn’t depend on the values.
@edgeFlag: A bitfieldl indicating which edges, if any, where touched by this motion event.
Move Up in List
DispatchTrackball(0, 0, 0, 0, -2, 0, 0, 0, 0, 0, 0, 0)
Move Down in List
DispatchTrackball(0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0)
DispatchKey(long downTime, long eventTime, int action, int code, int repeat, int metaState, int device, int scancode)
@downTime: at which this key code originally went down.
@eventTime: at which this event happened.
@action:
@code:
@repeat:
@metaState: The state of any meta/modifier keys that were in effect when the event was generated.
@deivce: The id for the devices that this event came from. An id of zero indicates that the evet didn’t come from a physical device; other numbers are arbitrary and you shouldn’t depend on the values.
@scancode:
type= user
count= 20
speed= 1.0
start data >>
LaunchActivity(usi.testtool.monkey, usi.testtool.monkey.MonkeyActivity)
UserWait(2000)
DispatchPointer(0, 0, 0, 222, 152, 0, 0, 0, 0, 0, 0, 0)
DispatchPointer(0, 0, 1, 222, 152, 0, 0, 0, 0, 0, 0, 0)
UserWait(2000)
DispatchKey(0, 0, 0, 38, 2, 0, 0, 0)
UserWait(2000)
DispatchKey(0, 0, 0, 39, 2, 0, 0, 0)
UserWait(2000)
DispatchKey(0, 0, 0, 37, 2, 0, 0, 0)
UserWait(6000)
DispatchPress(KEYCODE_HOME)
type= user
count= 20
speed= 1.0
start data >>
#click home button
captureDispatchKey(0, 0, 0, 3, 0, 0, 0, 0)
captureDispatchKey(0, 0, 1, 3, 0, 0, 0, 0)