转自https://blog.csdn.net/daihuimaozideren/article/details/77529345

(七)事件型指令 
事件类型指令可实现四个主要功能。

(1)复现随机事件

Monkey最大的特点就是伪随机。之所以加个“伪”字,是因为该随机事件可进行复现。 
我们每次执行一组随机事件,系统都会给一个随机的ID,称之为seed。例如

C:\Users\XXXX>adb shell monkey -p com.breakloop.butterknifedemo -v 100
:Monkey: seed=1503779100077 count=100
:AllowPackage: com.breakloop.butterknifedemo
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Event percentages:
....
## Network stats: elapsed time=83ms (0ms mobile, 0ms wifi, 83ms not connected)
// Monkey finishedC:\Users\XXXX>

若我们想将该组随机事件再次执行一遍,则使用-s+seed+count即可。

C:\Users\yisong>adb shell monkey -v -s 1503779100077 100
:Monkey: seed=1503779100077 count=100
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Event percentages:
...
## Network stats: elapsed time=588ms (0ms mobile, 0ms wifi, 588ms not connected)// Monkey finishedC:\Users\yisong>

除了执行事件不同,其他都与之前一样。

那么问题来了 
(a)如果seed后的count,与之前不同,执行结果会如何? 
若count变小,则从前往后,执行count个事件。 
若count变大,则在执行完后,补充执行差数个随机事件。 
(b)seed何时过期? 
重新连接设备,kill-server&start-server,重启手机,都不会对seed有影响。

(2)指定事件间隔

在相邻的两条随机事件之间,默认没有事件间隔。因此,有时会引起随机事件的注入失败。

:Sending Touch (ACTION_DOWN): 0:(736.0,455.0)// Injection Failed
:Sending Touch (ACTION_UP): 0:(736.2039,467.69113)// Injection Failed
:Sending Flip keyboardOpen=false
Got IOException performing flipjava.io.IOException: write failed: EINVAL (Invali
d argument)// Injection Failed
:Sending Touch (ACTION_DOWN): 0:(352.0,1698.0)// Injection Failed
:Sending Touch (ACTION_UP): 0:(349.23996,1686.784)// Injection Failed
:Sending Trackball (ACTION_MOVE): 0:(-5.0,-4.0)
:Sending Trackball (ACTION_UP): 0:(0.0,0.0)
:Sending Touch (ACTION_DOWN): 0:(788.0,1048.0)// Injection Failed
:Sending Touch (ACTION_UP): 0:(780.9308,1044.052)// Injection Failed
:Sending Trackball (ACTION_MOVE): 0:(0.0,-2.0)

为了避免这类情况,须在事件间添加“等待”。使用参数–throttle+时间间隔。 
throttle(油门)?应该命名为刹车吧。 
需要说明的是 
(a)参数前是两个“-”! 
(b)时间单位为毫秒

:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.vmall.client/.activity.VmallWa
pActivity;end// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.vmall.client/.activity.VmallWapActivity } in pac
kage com.vmall.client
Sleeping for 1000 milliseconds
:Sending Trackball (ACTION_MOVE): 0:(-5.0,-5.0)
:Sending Trackball (ACTION_MOVE): 0:(0.0,1.0)
:Sending Trackball (ACTION_MOVE): 0:(2.0,-5.0)
:Sending Trackball (ACTION_MOVE): 0:(-5.0,-4.0)
:Sending Trackball (ACTION_MOVE): 0:(2.0,-1.0)
:Sending Trackball (ACTION_MOVE): 0:(-3.0,1.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,4.0)
:Sending Trackball (ACTION_MOVE): 0:(-4.0,4.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,-2.0)
:Sending Trackball (ACTION_MOVE): 0:(3.0,-3.0)
:Sending Trackball (ACTION_DOWN): 0:(0.0,0.0)
:Sending Trackball (ACTION_UP): 0:(0.0,0.0)
Sleeping for 1000 milliseconds// Allowing start of Intent { cmp=com.vmall.client/.activity.PolicyWebActivi
ty } in package com.vmall.client
:Sending Key (ACTION_DOWN): 82    // KEYCODE_MENU
:Sending Key (ACTION_UP): 82    // KEYCODE_MENU
Sleeping for 1000 milliseconds
:Sending Touch (ACTION_DOWN): 0:(139.0,398.0)
:Sending Touch (ACTION_MOVE): 0:(157.42459,406.12418)
:Sending Touch (ACTION_MOVE): 0:(175.66505,407.0996)
:Sending Touch (ACTION_MOVE): 0:(185.49532,419.4165)
:Sending Touch (ACTION_MOVE): 0:(199.77296,435.93414)
:Sending Touch (ACTION_MOVE): 0:(215.76842,453.50436)
:Sending Touch (ACTION_MOVE): 0:(232.69334,470.774)
:Sending Touch (ACTION_MOVE): 0:(254.05827,476.62515)
:Sending Touch (ACTION_MOVE): 0:(262.36322,481.53244)
:Sending Touch (ACTION_UP): 0:(281.79745,489.0132)
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 82    // KEYCODE_MENU

注:从log来看,并不是所有的事件后都有“等待”。个人感觉,是在事件无法第一时间得到响应时,才去等待。

(3)指定某类事件所占比例

那么我们都有哪些事件呢? 
各个事件都代表什么操作? 
如果不设置事件比例,有没有默认的比例? 
我们来一一解释。

先来看一组随机事件LOG。

C:\Users\XXXX>adb shell monkey --throttle 1000 -v 10
:Monkey: seed=1503647257950 count=10
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Event percentages:
//   0: 15.0%
//   1: 10.0%
//   2: 2.0%
//   3: 15.0%
//   4: -0.0%
//   5: -0.0%
//   6: 25.0%
//   7: 15.0%
//   8: 2.0%
//   9: 2.0%
//   10: 1.0%
//   11: 13.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.huawei.android.findmyphone/.ui
.FindMyPhoneActivity;end// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.huawei.android.findmyphone/.ui.FindMyPhoneActivi
ty } in package com.huawei.android.findmyphone
:Sending Touch (ACTION_DOWN): 0:(236.0,163.0)
:Sending Touch (ACTION_UP): 0:(247.74335,163.03857)
:Sending Touch (ACTION_DOWN): 0:(819.0,1411.0)
:Sending Touch (ACTION_UP): 0:(825.0237,1402.9965)
:Sending Touch (ACTION_DOWN): 0:(745.0,1572.0)
Events injected: 10
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=5113ms (0ms mobile, 0ms wifi, 5113ms not connecte
d)
// Monkey finished

其中有一个Event percentages。可见,如果不使用–pct-XXXX指令,则按照默认比例触发随机事件。只是,不知道索引对应的事件是什么。

按照参数,可以分为八类。 
(a)–pct-touch:触摸事件。即在某一位置的Down-Up(手指的放下和抬起)事件。Down(ACTION_DOWN)和Up(ACTION_UP)的坐标临近,但并非相同。

C:\Users\XXXX>adb shell monkey --throttle 1000 -v --pct-touch 100 10
:Monkey: seed=1503671202592 count=10
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Event percentages:
//   0: 100.0%
//   1: 0.0%
//   2: 0.0%
//   3: 0.0%
//   4: -0.0%
//   5: -0.0%
//   6: 0.0%
//   7: 0.0%
//   8: 0.0%
//   9: 0.0%
//   10: 0.0%
//   11: 0.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.gemalto.qrcodelib/.MainActivit
y;end// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.gemalto.qrcodelib/.MainActivity } in package com
.gemalto.qrcodelib
:Sending Touch (ACTION_DOWN): 0:(186.0,781.0)
:Sending Touch (ACTION_UP): 0:(181.72902,780.3934)
:Sending Touch (ACTION_DOWN): 0:(600.0,384.0)
:Sending Touch (ACTION_UP): 0:(609.29193,385.8893)
:Sending Touch (ACTION_DOWN): 0:(786.0,1742.0)
:Sending Touch (ACTION_UP): 0:(782.567,1737.6458)
:Sending Touch (ACTION_DOWN): 0:(733.0,1538.0)
:Sending Touch (ACTION_UP): 0:(742.7612,1545.8889)
:Sending Touch (ACTION_DOWN): 0:(176.0,1538.0)
Events injected: 10
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=5093ms (0ms mobile, 0ms wifi, 5093ms not connecte
d)
// Monkey finished

(b)–pct-motion:动作事件。以Down(ACTION_DOWN)开始,Up(ACTION_UP)结尾,中间至少有一次Move(ACTION_MOVE)。

C:\Users\XXXX>adb shell monkey --throttle 1000 -v -v --pct-motion 100 10
:Monkey: seed=1503775969786 count=10
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Seeded: 1503775969786
// Event percentages:
//   0: 0.0%
//   1: 100.0%
//   2: 0.0%
//   3: 0.0%
//   4: -0.0%
//   5: -0.0%
//   6: 0.0%
//   7: 0.0%
//   8: 0.0%
//   9: 0.0%
//   10: 0.0%
//   11: 0.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.huawei.android.remotecontrolle
r/.StartActivity;end// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.huawei.android.remotecontroller/.StartActivity }in package com.huawei.android.remotecontroller
Sleeping for 1000 milliseconds// Allowing start of Intent { cmp=com.huawei.android.remotecontroller/.app.W
elcomeActivity } in package com.huawei.android.remotecontroller// activityResuming(com.huawei.android.remotecontroller)
:Sending Touch (ACTION_DOWN): 0:(241.0,1334.0)
:Sending Touch (ACTION_MOVE): 0:(245.10721,1333.8828)
:Sending Touch (ACTION_MOVE): 0:(246.83798,1331.2542)
:Sending Touch (ACTION_MOVE): 0:(248.75221,1324.734)
:Sending Touch (ACTION_MOVE): 0:(249.26602,1323.9482)
:Sending Touch (ACTION_MOVE): 0:(251.57216,1317.7059)
:Sending Touch (ACTION_MOVE): 0:(255.50874,1314.2244)
:Sending Touch (ACTION_UP): 0:(259.62653,1307.603)
Sleeping for 1000 milliseconds
:Sending Touch (ACTION_DOWN): 0:(1031.0,1108.0)
Events injected: 10
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=2060ms (0ms mobile, 0ms wifi, 2060ms not connecte
d)
// Monkey finished

(c)–pct-trackball:轨迹球事件。即单纯的Move(ACTION_MOVE)。

C:\Users\XXXX>adb shell monkey --throttle 1000 -v -v --pct-trackball 100 10
:Monkey: seed=1503665474331 count=10
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Seeded: 1503665474331
// Event percentages:
//   0: 0.0%
//   1: 0.0%
//   2: 0.0%
//   3: 100.0%
//   4: -0.0%
//   5: -0.0%
//   6: 0.0%
//   7: 0.0%
//   8: 0.0%
//   9: 0.0%
//   10: 0.0%
//   11: 0.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.yunos.cloudkit.demo/.MainActiv
ity;end// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.yunos.cloudkit.demo/.MainActivity } in package c
om.yunos.cloudkit.demo
Sleeping for 1000 milliseconds
:Sending Trackball (ACTION_MOVE): 0:(-5.0,-3.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,1.0)
:Sending Trackball (ACTION_MOVE): 0:(-1.0,3.0)
:Sending Trackball (ACTION_MOVE): 0:(2.0,-1.0)
:Sending Trackball (ACTION_MOVE): 0:(-4.0,3.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,-3.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,-4.0)
:Sending Trackball (ACTION_MOVE): 0:(-4.0,-3.0)
:Sending Trackball (ACTION_MOVE): 0:(-2.0,-3.0)
Events injected: 10
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=1045ms (0ms mobile, 0ms wifi, 1045ms not connecte
d)
// Monkey finished

(d)–pct-nav:基本导航事件。即来自于方向输入设备的上下左右操作。

C:\Users\XXXX>adb shell monkey --throttle 1000 -v -v --pct-nav 100 10
:Monkey: seed=1503699935813 count=10
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Seeded: 1503699935813
// Event percentages:
//   0: 0.0%
//   1: 0.0%
//   2: 0.0%
//   3: 0.0%
//   4: -0.0%
//   5: -0.0%
//   6: 100.0%
//   7: 0.0%
//   8: 0.0%
//   9: 0.0%
//   10: 0.0%
//   11: 0.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.gto.paltesttoolui/com.gto.tsm.
instrumentation.EmmaInstrumentation%24InstrumentedActivity;end// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.gto.paltesttoolui/com.gto.tsm.instrumentation.Em
maInstrumentation$InstrumentedActivity } in package com.gto.paltesttoolui
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 22    // KEYCODE_DPAD_RIGHT
:Sending Key (ACTION_UP): 22    // KEYCODE_DPAD_RIGHT
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 22    // KEYCODE_DPAD_RIGHT
:Sending Key (ACTION_UP): 22    // KEYCODE_DPAD_RIGHT
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 20    // KEYCODE_DPAD_DOWN
:Sending Key (ACTION_UP): 20    // KEYCODE_DPAD_DOWN
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 21    // KEYCODE_DPAD_LEFT
:Sending Key (ACTION_UP): 21    // KEYCODE_DPAD_LEFT
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 21    // KEYCODE_DPAD_LEFT
Events injected: 10
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=5116ms (0ms mobile, 0ms wifi, 5116ms not connecte
d)
// Monkey finished

(e)–pct-majornav:主导航事件。即Navigation Bar的确认,菜单,返回键等。

C:\Users\XXXX>adb shell monkey --throttle 1000 -v -v --pct-majornav 100 10
:Monkey: seed=1503700822988 count=10
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Seeded: 1503700822988
// Event percentages:
//   0: 0.0%
//   1: 0.0%
//   2: 0.0%
//   3: 0.0%
//   4: -0.0%
//   5: -0.0%
//   6: 0.0%
//   7: 100.0%
//   8: 0.0%
//   9: 0.0%
//   10: 0.0%
//   11: 0.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.android.settings/.HWSettings;e
nd// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.android.settings/.HWSettings } in package com.an
droid.settings
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 82    // KEYCODE_MENU
:Sending Key (ACTION_UP): 82    // KEYCODE_MENU
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 82    // KEYCODE_MENU
:Sending Key (ACTION_UP): 82    // KEYCODE_MENU
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 23    // KEYCODE_DPAD_CENTER
:Sending Key (ACTION_UP): 23    // KEYCODE_DPAD_CENTER
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 82    // KEYCODE_MENU
:Sending Key (ACTION_UP): 82    // KEYCODE_MENU
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 23    // KEYCODE_DPAD_CENTER
Events injected: 10
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=5100ms (0ms mobile, 0ms wifi, 5100ms not connecte
d)
// Monkey finished

(f)–pct-syskeys:系统按键事件。即系统保留按键,如HOME键,BACK键,拨号键,挂断键,音量键等。

C:\Users\XXXX>adb shell monkey -v -v --pct-syskeys 100 10
:Monkey: seed=1503762438503 count=10
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Seeded: 1503762438503
// Event percentages:
//   0: 0.0%
//   1: 0.0%
//   2: 0.0%
//   3: 0.0%
//   4: -0.0%
//   5: -0.0%
//   6: 0.0%
//   7: 0.0%
//   8: 100.0%
//   9: 0.0%
//   10: 0.0%
//   11: 0.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.huawei.phoneservice/.ui.HelpCe
nterActivity;end// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.huawei.phoneservice/.ui.HelpCenterActivity } in
package com.huawei.phoneservice
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 24    // KEYCODE_VOLUME_UP// Allowing start of Intent { cmp=com.huawei.phoneservice/com.huawei.phonese
rviceuni.start.UserAgreementActivity } in package com.huawei.phoneservice
:Sending Key (ACTION_UP): 24    // KEYCODE_VOLUME_UP
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 25    // KEYCODE_VOLUME_DOWN
:Sending Key (ACTION_UP): 25    // KEYCODE_VOLUME_DOWN
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 25    // KEYCODE_VOLUME_DOWN
:Sending Key (ACTION_UP): 25    // KEYCODE_VOLUME_DOWN
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 24    // KEYCODE_VOLUME_UP
:Sending Key (ACTION_UP): 24    // KEYCODE_VOLUME_UP
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 24    // KEYCODE_VOLUME_UP
Events injected: 10
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=765ms (0ms mobile, 0ms wifi, 765ms not connected)// Monkey finished

(g)–pct-appswitch:应用启动事件

C:\Users\XXXX>adb shell monkey -v --pct-appswitch 100 3
:Monkey: seed=1503724767031 count=3
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Event percentages:
//   0: 0.0%
//   1: 0.0%
//   2: 0.0%
//   3: 0.0%
//   4: -0.0%
//   5: -0.0%
//   6: 0.0%
//   7: 0.0%
//   8: 0.0%
//   9: 100.0%
//   10: 0.0%
//   11: 0.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.cate
ory.LAUNCHER;launchFlags=0x10200000;component=com.huawei.fans/.activity.MainAct
vity;end// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.i
tent.category.LAUNCHER] cmp=com.huawei.fans/.activity.MainActivity } in package
com.huawei.fans
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.cate
ory.LAUNCHER;launchFlags=0x10200000;component=com.huawei.appmarket/.MainActivit
;end// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.i
tent.category.LAUNCHER] cmp=com.huawei.appmarket/.MainActivity } in package com
huawei.appmarket
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.cate
ory.LAUNCHER;launchFlags=0x10200000;component=com.android.soundrecorder/.SoundR
corder;end// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.i
tent.category.LAUNCHER] cmp=com.android.soundrecorder/.SoundRecorder } in packa
e com.android.soundrecorder
Events injected: 3
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=75ms (0ms mobile, 0ms wifi, 75ms not connected)
// Monkey finished

(h)–pct-anyevent:其他未提及事件。该事件可能包含其他上述事件。

C:\Users\XXXX>adb shell monkey -v -v --pct-anyevent 100 10
:Monkey: seed=1503761055148 count=10
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Seeded: 1503761055148
// Event percentages:
//   0: 0.0%
//   1: 0.0%
//   2: 0.0%
//   3: 0.0%
//   4: -0.0%
//   5: -0.0%
//   6: 0.0%
//   7: 0.0%
//   8: 0.0%
//   9: 0.0%
//   10: 0.0%
//   11: 100.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.huawei.health/.MainActivity;en
d// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.huawei.health/.MainActivity } in package com.hua
wei.health
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 549    // 549
:Sending Key (ACTION_UP): 549    // 549
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 507    // 507
:Sending Key (ACTION_UP): 507    // 507
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 362    // 362
:Sending Key (ACTION_UP): 362    // 362
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 673    // 673
:Sending Key (ACTION_UP): 673    // 673
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 25    // KEYCODE_VOLUME_DOWN
Events injected: 10
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=691ms (0ms mobile, 0ms wifi, 691ms not connected)// Monkey finished

仔细观察各个事件的Log,不难发现: 
(I)所有随机事件,若count>0,第一个事件永远是appswitch。必须要有一个activity作为操作对象!! 
(II)将某种事件所占百分比,调至100,可得出事件索引对应关系。 
0–> –pct-touch 
1–> –pct-motion 
3–> –pct-trackball 
6–> –pct-nav 
7–> –pct-majornav 
8–> –pct-syskeys 
9–> –pct-appswitch 
11–> –pct-anyevent

(III)若使用一个-v,ACTION_MOVE事件或KEYCODE_DPAD_XXXX不会显示在LOG中。

(4)执行脚本

使用参数-f来指定脚本path。

adb shell monkey -f c:\d\test 100

文件可用没有后缀名。 
注:此时count=100,是指将该脚本执行100次。

对于脚本的编写,我们将用单独的篇幅来讲解。

Monkey详解(事件型指令篇)-转相关推荐

  1. 一文详解JavaBean 看这篇就够了

    一文详解JavaBean 看这篇就够了 JavaBean的历史渊源 JavaBean的定义(通俗版) JavaBean应用 < jsp:useBean > < jsp:getProp ...

  2. AngularJS 详解Directive(指令)机制

    AngularJS  5个实例详解Directive(指令)机制 大漠穷秋  http://damoqiongqiu.iteye.com/blog/1917971 1.一点小说明 指令的作用:实现语义 ...

  3. Android测试工具-Monkey详解

    Monkey详解 Monkey详解 一 Monkey简介 二 Monkey测试环境配置 三 执行Monkey 四 常用monkey命令 五 Monkey测试问题分析 Monkey详解 一 Monkey ...

  4. Matplot pyplot绘制单图,多子图不同样式详解,这一篇就够了

    Matplot pyplot绘制单图,多子图不同样式详解,这一篇就够了 1. 单图单线 2. 单图多线不同样式(红色圆圈.蓝色实线.绿色三角等) 3. 使用关键字字符串绘图(data 可指定依赖值为: ...

  5. SCCM 2007 R2部署、操作详解系列之部署篇

    SCCM 2007 R2部署.操作详解系列之部署篇 导语: 大家好,我是John Cai(蔡建涛),欢迎大家来到我的博客-E网情深http://johncai.blog.51cto.com/.今天,我 ...

  6. 代理后台中间件_Golang Gin 实战(十三)| 中间件详解看这一篇就够了

    6000字大章带你死磕Golang Gin中间件 在Gin的整个实现中,中间件可谓是Gin的精髓.一个个中间件组成一条中间件链,对HTTP Request请求进行拦截处理,实现了代码的解耦和分离,并且 ...

  7. 2016年最新苹果开发者账号注册流程详解(公司账号篇)

    随着苹果规定金融/理财类应用需要使用公司开发者账号上传,并进一步加大对此类问题的审核力度,公司开发者账号开始呈现出炙手可热之势! 不过,公司开发者账号的注册流程着实复杂--不仅要填写公司的D-U-N- ...

  8. Linux磁盘分区论文3000字,磁盘分区对齐详解与配置 – Linux篇

    磁盘分区对齐详解与配置 – Linux篇 介绍 许多系统管理员可能不曾听过磁盘分区对齐之说,甚至一些有经验的存储管理员对分区对齐也不甚了解.磁盘分区不对齐现象是什么,为什么会造成比较严重的性能下降?相 ...

  9. android压力测试命令monkey详解

    本文转载自 腾讯优测  原文地址 http://bbs.utest.qq.com/?p=16 这篇文章主要介绍了android monkey命令详解,Monkey 就是SDK中附带的一个工具,该工具主 ...

最新文章

  1. haproxy ssl_我们如何微调HAProxy以实现2,000,000个并发SSL连接
  2. python tqdm添加进度条
  3. mysql体系结构:
  4. 悖论对计算机科学影响,科学网—基于对角线引理和维特根斯坦思想对于悖论的分析 - 庄朝晖的博文...
  5. C#windows服务开发
  6. Redis常用概念简介
  7. Android 系统(184)---Android APN 配置
  8. “9元课程”拼凑起来的暑假和K12在线教育企业的生死营销战
  9. Spark 在 Window 环境下的搭建
  10. SqlServer还原数据库出现“无法在服务器上访问指定的路径或文件”提示的解决办法
  11. 正则对字符串中手机号加密
  12. XRD测试的68个问题(四)
  13. OSChina 周三乱弹 ——找女朋友都是双胞胎
  14. linux 韦恩图两个,在线&在R中绘制韦恩图的几种方法 和 一些漂亮的venn图
  15. mongodb的java驱动_MongoDB的java版本驱动
  16. C语言基本的语法规定
  17. 哈工大李治军老师操作系统笔记【10】:内核级线程实现(Learning OS Concepts By Coding Them !)
  18. response输出文件的时候,解决迅雷下载的问题
  19. gta5怎么设置画质最好_GTA5:如何让你的游戏画质更好,游戏更顺手,一波设置教给大家!...
  20. Android齐刘海适配完全攻略

热门文章

  1. 美国空军如何在45天内在F-16战斗机上部署Kubernetes与Istio
  2. 【CloudCompare教程】015:计算点云曲率(地表曲率)
  3. python求一组数中最大数_Python查找数组中最大的数
  4. 如何制作电子相册发到微信?快速上手教程,效果酷炫刷爆朋友圈
  5. 富兰克林邓普顿向区块链初创公司Proof of Impact投资了未公开的金额
  6. GitHub使用教程含加速方法
  7. 45页新能源充电桩运营平台规划与建设方案
  8. python显示图片透明度怎么调,如何使jpg图像半透明?
  9. 可运行war包,命令行启动war包
  10. 华清远见-重庆中心-JavaWeb综合阶段技术总结