Repository navigation
Expand file tree
/
Copy pathcoordinatesBasedAutomation.json
More file actions
814 lines (814 loc) · 28.6 KB
/
Copy pathcoordinatesBasedAutomation.json
File metadata and controls
814 lines (814 loc) · 28.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
{
"source": "../api/coordinatesBasedAutomation.md",
"modules": [
{
"textRaw": "基于坐标的触摸模拟",
"name": "基于坐标的触摸模拟",
"stability": 2,
"stabilityText": "Stable",
"desc": "<p>本章节介绍了一些使用坐标进行点击、滑动的函数。这些函数有的需要安卓7.0以上,有的需要root权限。</p>\n<p>要获取要点击的位置的坐标,可以在开发者选项中开启"指针位置"。</p>\n<p>基于坐标的脚本通常会有分辨率的问题,这时可以通过<code>setScreenMetrics()</code>函数来进行自动坐标放缩。这个函数会影响本章节的所有点击、长按、滑动等函数。通过设定脚本设计时的分辨率,使得脚本在其他分辨率下自动放缩坐标。</p>\n<p>控件和坐标也可以相互结合。一些控件是无法点击的(clickable为false), 无法通过<code>.click()</code>函数来点击,这时如果安卓版本在7.0以上或者有root权限,就可以通过以下方式来点击:</p>\n<pre><code>//获取这个控件\nvar widget = id("xxx").findOne();\n//获取其中心位置并点击\nclick(widget.bounds().centerX(), widget.bounds().centerY());\n//如果用root权限则用Tap\n</code></pre>",
"methods": [
{
"textRaw": "setScreenMetrics(width, height)",
"type": "method",
"name": "setScreenMetrics",
"signatures": [
{
"params": [
{
"textRaw": "width {number} 屏幕宽度,单位像素 ",
"name": "width",
"type": "number",
"desc": "屏幕宽度,单位像素"
},
{
"textRaw": "height {number} 屏幕高度,单位像素 ",
"name": "height",
"type": "number",
"desc": "屏幕高度,单位像素"
}
]
},
{
"params": [
{
"name": "width"
},
{
"name": "height"
}
]
}
],
"desc": "<p>设置脚本坐标点击所适合的屏幕宽高。如果脚本运行时,屏幕宽度不一致会自动放缩坐标。</p>\n<p>例如在1920*1080的设备中,某个操作的代码为</p>\n<pre><code>setScreenMetrics(1080, 1920);\nclick(800, 200);\nlongClick(300, 500);\n</code></pre><p>那么在其他设备上AutoJs会自动放缩坐标以便脚本仍然有效。例如在540 * 960的屏幕中<code>click(800, 200)</code>实际上会点击位置(400, 100)。</p>\n"
}
],
"type": "module",
"displayName": "基于坐标的触摸模拟"
},
{
"textRaw": "RootAutomator",
"name": "rootautomator",
"stability": 2,
"stabilityText": "Stable",
"desc": "<p>RootAutomator是一个使用root权限来模拟触摸的对象,用它可以完成触摸与多点触摸,并且这些动作的执行没有延迟。</p>\n<p>一个脚本中最好只存在一个RootAutomator,并且保证脚本结束退出他。可以在exit事件中退出RootAutomator,例如:</p>\n<pre><code>var ra = new RootAutomator();\nevents.on('exit', function(){\n ra.exit();\n});\n//执行一些点击操作\n...\n\n</code></pre><p><strong>注意以下命令需要root权限</strong></p>\n",
"methods": [
{
"textRaw": "RootAutomator.tap(x, y[, id])",
"type": "method",
"name": "tap",
"signatures": [
{
"params": [
{
"textRaw": "`x` {number} 横坐标 ",
"name": "x",
"type": "number",
"desc": "横坐标"
},
{
"textRaw": "`y` {number} 纵坐标 ",
"name": "y",
"type": "number",
"desc": "纵坐标"
},
{
"textRaw": "`id` {number} 多点触摸id,可选,默认为1,可以通过setDefaultId指定。 ",
"name": "id",
"type": "number",
"desc": "多点触摸id,可选,默认为1,可以通过setDefaultId指定。",
"optional": true
}
]
},
{
"params": [
{
"name": "x"
},
{
"name": "y"
},
{
"name": "id",
"optional": true
}
]
}
],
"desc": "<p>点击位置(x, y)。其中id是一个整数值,用于区分多点触摸,不同的id表示不同的"手指",例如:</p>\n<pre><code>var ra = new RootAutomator();\n//让"手指1"点击位置(100, 100)\nra.tap(100, 100, 1);\n//让"手指2"点击位置(200, 200);\nra.tap(200, 200, 2);\nra.exit();\n</code></pre><p>如果不需要多点触摸,则不需要id这个参数。\n多点触摸通常用于手势或游戏操作,例如模拟双指捏合、双指上滑等。</p>\n<p>某些情况下可能存在tap点击无反应的情况,这时可以用<code>RootAutomator.press()</code>函数代替。</p>\n"
},
{
"textRaw": "RootAutomator.swipe(x1, x2, y1, y2[, duration, id])",
"type": "method",
"name": "swipe",
"signatures": [
{
"params": [
{
"textRaw": "`x1` {number} 滑动起点横坐标 ",
"name": "x1",
"type": "number",
"desc": "滑动起点横坐标"
},
{
"textRaw": "`y1` {number} 滑动起点纵坐标 ",
"name": "y1",
"type": "number",
"desc": "滑动起点纵坐标"
},
{
"textRaw": "`x2` {number} 滑动终点横坐标 ",
"name": "x2",
"type": "number",
"desc": "滑动终点横坐标"
},
{
"textRaw": "`y2` {number} 滑动终点纵坐标 ",
"name": "y2",
"type": "number",
"desc": "滑动终点纵坐标"
},
{
"textRaw": "`duration` {number} 滑动时长,单位毫秒,默认值为300 ",
"name": "duration",
"type": "number",
"desc": "滑动时长,单位毫秒,默认值为300",
"optional": true
},
{
"textRaw": "`id` {number} 多点触摸id,可选,默认为1 ",
"name": "id",
"type": "number",
"desc": "多点触摸id,可选,默认为1",
"optional": true
}
]
},
{
"params": [
{
"name": "x1"
},
{
"name": "x2"
},
{
"name": "y1"
},
{
"name": "y2"
},
{
"name": "duration",
"optional": true
},
{
"name": "id",
"optional": true
}
]
}
],
"desc": "<p>模拟一次从(x1, y1)到(x2, y2)的时间为duration毫秒的滑动。</p>\n"
},
{
"textRaw": "RootAutomator.press(x, y, duration[, id])",
"type": "method",
"name": "press",
"signatures": [
{
"params": [
{
"textRaw": "`x` {number} 横坐标 ",
"name": "x",
"type": "number",
"desc": "横坐标"
},
{
"textRaw": "`y` {number} 纵坐标 ",
"name": "y",
"type": "number",
"desc": "纵坐标"
},
{
"textRaw": "`duration` {number} 按下时长 ",
"name": "duration",
"type": "number",
"desc": "按下时长"
},
{
"textRaw": "`id` {number} 多点触摸id,可选,默认为1 ",
"name": "id",
"type": "number",
"desc": "多点触摸id,可选,默认为1",
"optional": true
}
]
},
{
"params": [
{
"name": "x"
},
{
"name": "y"
},
{
"name": "duration"
},
{
"name": "id",
"optional": true
}
]
}
],
"desc": "<p>模拟按下位置(x, y),时长为duration毫秒。</p>\n"
},
{
"textRaw": "RootAutomator.longPress(x, y[\\, id\\])",
"type": "method",
"name": "longPress",
"signatures": [
{
"params": [
{
"textRaw": "`x` {number} 横坐标 ",
"name": "x",
"type": "number",
"desc": "横坐标"
},
{
"textRaw": "`y` {number} 纵坐标 ",
"name": "y",
"type": "number",
"desc": "纵坐标"
},
{
"textRaw": "`duration` {number} 按下时长 ",
"name": "duration",
"type": "number",
"desc": "按下时长"
},
{
"textRaw": "`id` {number} 多点触摸id,可选,默认为1 ",
"name": "id",
"type": "number",
"desc": "多点触摸id,可选,默认为1"
}
]
},
{
"params": [
{
"name": "x"
},
{
"name": "y[\\"
},
{
"name": "id\\"
}
]
}
],
"desc": "<p>模拟长按位置(x, y)。</p>\n<p>以上为简单模拟触摸操作的函数。如果要模拟一些复杂的手势,需要更底层的函数。</p>\n"
},
{
"textRaw": "RootAutomator.touchDown(x, y[, id])",
"type": "method",
"name": "touchDown",
"signatures": [
{
"params": [
{
"textRaw": "`x` {number} 横坐标 ",
"name": "x",
"type": "number",
"desc": "横坐标"
},
{
"textRaw": "`y` {number} 纵坐标 ",
"name": "y",
"type": "number",
"desc": "纵坐标"
},
{
"textRaw": "`id` {number} 多点触摸id,可选,默认为1 ",
"name": "id",
"type": "number",
"desc": "多点触摸id,可选,默认为1",
"optional": true
}
]
},
{
"params": [
{
"name": "x"
},
{
"name": "y"
},
{
"name": "id",
"optional": true
}
]
}
],
"desc": "<p>模拟手指按下位置(x, y)。</p>\n"
},
{
"textRaw": "RootAutomator.touchMove(x, y[, id])",
"type": "method",
"name": "touchMove",
"signatures": [
{
"params": [
{
"textRaw": "`x` {number} 横坐标 ",
"name": "x",
"type": "number",
"desc": "横坐标"
},
{
"textRaw": "`y` {number} 纵坐标 ",
"name": "y",
"type": "number",
"desc": "纵坐标"
},
{
"textRaw": "`id` {number} 多点触摸id,可选,默认为1 ",
"name": "id",
"type": "number",
"desc": "多点触摸id,可选,默认为1",
"optional": true
}
]
},
{
"params": [
{
"name": "x"
},
{
"name": "y"
},
{
"name": "id",
"optional": true
}
]
}
],
"desc": "<p>模拟移动手指到位置(x, y)。</p>\n"
},
{
"textRaw": "RootAutomator.touchUp([id])",
"type": "method",
"name": "touchUp",
"signatures": [
{
"params": [
{
"textRaw": "`id` {number} 多点触摸id,可选,默认为1 ",
"name": "id",
"type": "number",
"desc": "多点触摸id,可选,默认为1",
"optional": true
}
]
},
{
"params": [
{
"name": "id",
"optional": true
}
]
}
],
"desc": "<p>模拟手指弹起。</p>\n"
}
],
"type": "module",
"displayName": "RootAutomator"
},
{
"textRaw": "使用root权限点击和滑动的简单命令",
"name": "使用root权限点击和滑动的简单命令",
"stability": 1,
"stabilityText": "Experimental",
"desc": "<p>注意:本章节的函数在后续版本很可能有改动!请勿过分依赖本章节函数的副作用。推荐使用<code>RootAutomator</code>代替本章节的触摸函数。</p>\n<p>以下函数均需要root权限,可以实现任意位置的点击、滑动等。</p>\n<ul>\n<li>这些函数通常首字母大写以表示其特殊的权限。 </li>\n<li>这些函数均不返回任何值。 </li>\n<li>并且,这些函数的执行是异步的、非阻塞的,在不同机型上所用的时间不同。脚本不会等待动作执行完成才继续执行。因此最好在每个函数之后加上适当的sleep来达到期望的效果。</li>\n</ul>\n<p>例如:</p>\n<pre><code>Tap(100, 100);\nsleep(500);\n</code></pre><p>注意,动作的执行可能无法被停止,例如:</p>\n<pre><code>for(var i = 0; i < 100; i++){\n Tap(100, 100);\n}\n</code></pre><p>这段代码执行后可能会出现在任务管理中停止脚本后点击仍然继续的情况。\n因此,强烈建议在每个动作后加上延时:</p>\n<pre><code>for(var i = 0; i < 100; i++){\n Tap(100, 100);\n sleep(500);\n}\n</code></pre>",
"methods": [
{
"textRaw": "Tap(x, y)",
"type": "method",
"name": "Tap",
"signatures": [
{
"params": [
{
"textRaw": "x, y {number} 要点击的坐标。 ",
"name": "x,",
"desc": "y {number} 要点击的坐标。"
},
{
"name": "y"
}
]
},
{
"params": [
{
"name": "x"
},
{
"name": "y"
}
]
}
],
"desc": "<p>点击位置(x, y), 您可以通过"开发者选项"开启指针位置来确定点击坐标。</p>\n"
},
{
"textRaw": "Swipe(x1, y1, x2, y2, \\[duration\\])",
"type": "method",
"name": "Swipe",
"signatures": [
{
"params": [
{
"textRaw": "x1, y1 {number} 滑动起点的坐标 ",
"name": "x1,",
"desc": "y1 {number} 滑动起点的坐标"
},
{
"textRaw": "x2, y2 {number} 滑动终点的坐标 ",
"name": "x2,",
"desc": "y2 {number} 滑动终点的坐标"
},
{
"textRaw": "duration {number} 滑动动作所用的时间 ",
"name": "duration",
"type": "number",
"desc": "滑动动作所用的时间"
},
{
"name": "y2"
},
{
"name": "\\[duration\\"
}
]
},
{
"params": [
{
"name": "x1"
},
{
"name": "y1"
},
{
"name": "x2"
},
{
"name": "y2"
},
{
"name": "\\[duration\\"
}
]
}
],
"desc": "<p>滑动。从(x1, y1)位置滑动到(x2, y2)位置。</p>\n"
}
],
"type": "module",
"displayName": "使用root权限点击和滑动的简单命令"
}
],
"properties": [
{
"textRaw": "安卓7.0以上的触摸和手势模拟",
"type": "property",
"name": "0以上的触摸和手势模拟",
"stability": 2,
"stabilityText": "Stable",
"desc": "<p><strong>注意以下命令只有Android7.0及以上才有效</strong></p>\n",
"methods": [
{
"textRaw": "click(x, y)",
"type": "method",
"name": "click",
"signatures": [
{
"params": [
{
"textRaw": "`x` {number} 要点击的坐标的x值 ",
"name": "x",
"type": "number",
"desc": "要点击的坐标的x值"
},
{
"textRaw": "`y` {number} 要点击的坐标的y值 ",
"name": "y",
"type": "number",
"desc": "要点击的坐标的y值"
}
]
},
{
"params": [
{
"name": "x"
},
{
"name": "y"
}
]
}
],
"desc": "<p>模拟点击坐标(x, y),并返回是否点击成功。只有在点击执行完成后脚本才继续执行。</p>\n<p>一般而言,只有点击过程(大约150毫秒)中被其他事件中断(例如用户自行点击)才会点击失败。</p>\n<p>使用该函数模拟连续点击时可能有点击速度过慢的问题,这时可以用<code>press()</code>函数代替。</p>\n"
},
{
"textRaw": "longClick(x, y)",
"type": "method",
"name": "longClick",
"signatures": [
{
"params": [
{
"textRaw": "`x` {number} 要长按的坐标的x值 ",
"name": "x",
"type": "number",
"desc": "要长按的坐标的x值"
},
{
"textRaw": "`y` {number} 要长按的坐标的y值 ",
"name": "y",
"type": "number",
"desc": "要长按的坐标的y值"
}
]
},
{
"params": [
{
"name": "x"
},
{
"name": "y"
}
]
}
],
"desc": "<p>模拟长按坐标(x, y), 并返回是否成功。只有在长按执行完成(大约600毫秒)时脚本才会继续执行。</p>\n<p>一般而言,只有长按过程中被其他事件中断(例如用户自行点击)才会长按失败。</p>\n"
},
{
"textRaw": "press(x, y, duration)",
"type": "method",
"name": "press",
"signatures": [
{
"params": [
{
"textRaw": "`x` {number} 要按住的坐标的x值 ",
"name": "x",
"type": "number",
"desc": "要按住的坐标的x值"
},
{
"textRaw": "`y` {number} 要按住的坐标的y值 ",
"name": "y",
"type": "number",
"desc": "要按住的坐标的y值"
},
{
"textRaw": "`duration` {number} 按住时长,单位毫秒 ",
"name": "duration",
"type": "number",
"desc": "按住时长,单位毫秒"
}
]
},
{
"params": [
{
"name": "x"
},
{
"name": "y"
},
{
"name": "duration"
}
]
}
],
"desc": "<p>模拟按住坐标(x, y), 并返回是否成功。只有按住操作执行完成时脚本才会继续执行。</p>\n<p>如果按住时间过短,那么会被系统认为是点击;如果时长超过500毫秒,则认为是长按。</p>\n<p>一般而言,只有按住过程中被其他事件中断才会操作失败。</p>\n<p>一个连点器的例子如下:</p>\n<pre><code>//循环100次\nfor(var i = 0; i < 100; i++){\n //点击位置(500, 1000), 每次用时1毫秒\n press(500, 1000, 1);\n}\n</code></pre>"
},
{
"textRaw": "swipe(x1, y1, x2, y2, duration)",
"type": "method",
"name": "swipe",
"signatures": [
{
"params": [
{
"textRaw": "`x1` {number} 滑动的起始坐标的x值 ",
"name": "x1",
"type": "number",
"desc": "滑动的起始坐标的x值"
},
{
"textRaw": "`y1` {number} 滑动的起始坐标的y值 ",
"name": "y1",
"type": "number",
"desc": "滑动的起始坐标的y值"
},
{
"textRaw": "`x2` {number} 滑动的结束坐标的x值 ",
"name": "x2",
"type": "number",
"desc": "滑动的结束坐标的x值"
},
{
"textRaw": "`y2` {number} 滑动的结束坐标的y值 ",
"name": "y2",
"type": "number",
"desc": "滑动的结束坐标的y值"
},
{
"textRaw": "`duration` {number} 滑动时长,单位毫秒 ",
"name": "duration",
"type": "number",
"desc": "滑动时长,单位毫秒"
}
]
},
{
"params": [
{
"name": "x1"
},
{
"name": "y1"
},
{
"name": "x2"
},
{
"name": "y2"
},
{
"name": "duration"
}
]
}
],
"desc": "<p>模拟从坐标(x1, y1)滑动到坐标(x2, y2),并返回是否成功。只有滑动操作执行完成时脚本才会继续执行。</p>\n<p>一般而言,只有滑动过程中被其他事件中断才会滑动失败。</p>\n"
},
{
"textRaw": "gesture(duration, [x1, y1], [x2, y2], ...)",
"type": "method",
"name": "gesture",
"signatures": [
{
"params": [
{
"textRaw": "`duration` {number} 手势的时长 ",
"name": "duration",
"type": "number",
"desc": "手势的时长"
},
{
"textRaw": "[x, y] ... 手势滑动路径的一系列坐标 ",
"name": "[x,",
"desc": "y] ... 手势滑动路径的一系列坐标",
"optional": true
},
{
"name": "y1",
"optional": true
},
{
"name": "x2",
"optional": true
},
{
"name": "y2",
"optional": true
},
{
"name": "..."
}
]
},
{
"params": [
{
"name": "duration"
},
{
"name": "x1",
"optional": true
},
{
"name": "y1",
"optional": true
},
{
"name": "x2",
"optional": true
},
{
"name": "y2",
"optional": true
},
{
"name": "..."
}
]
}
],
"desc": "<p>模拟手势操作。例如<code>gesture(1000, [0, 0], [500, 500], [500, 1000])</code>为模拟一个从(0, 0)到(500, 500)到(500, 100)的手势操作,时长为2秒。</p>\n"
},
{
"textRaw": "gestures([delay1, duration1, [x1, y1], [x2, y2], ...], [delay2, duration2, [x3, y3], [x4, y4], ...], ...)",
"type": "method",
"name": "gestures",
"desc": "<p>同时模拟多个手势。每个手势的参数为[delay, duration, 坐标], delay为延迟多久(毫秒)才执行该手势;duration为手势执行时长;坐标为手势经过的点的坐标。其中delay参数可以省略,默认为0。</p>\n<p>例如手指捏合:</p>\n<pre><code>gestures([0, 500, [800, 300], [500, 1000]],\n [0, 500, [300, 1500], [500, 1000]]);\n</code></pre>",
"signatures": [
{
"params": [
{
"name": "delay1",
"optional": true
},
{
"name": "duration1",
"optional": true
},
{
"name": "x1",
"optional": true
},
{
"name": "y1",
"optional": true
},
{
"name": "x2",
"optional": true
},
{
"name": "y2",
"optional": true
},
{
"name": "...",
"optional": true
},
{
"name": "delay2",
"optional": true
},
{
"name": "duration2",
"optional": true
},
{
"name": "x3",
"optional": true
},
{
"name": "y3",
"optional": true
},
{
"name": "x4",
"optional": true
},
{
"name": "y4",
"optional": true
},
{
"name": "...",
"optional": true
},
{
"name": "..."
}
]
}
]
}
]
}
]
}