-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathexample.py
More file actions
70 lines (48 loc) · 1.44 KB
/
example.py
File metadata and controls
70 lines (48 loc) · 1.44 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
# -*- coding: utf-8 -*-
import auto_bot
import time
import random
from common.KeyCode import KeyCode
def touch_example():
# 轻触
auto_bot.tap(887, 1664)
# 滑动
auto_bot.swipe_time(887, 1664, 200, 1664, 200)
auto_bot.swipe_time(543, 1536, 543, 1536, 710)
def key_press_example():
# 按键模拟
auto_bot.key(KeyCode.KEYCODE_HOME.value)
def text_example():
# 文字输入
auto_bot.text("&*test#@? 'c")
def main():
ltc = time.localtime()
auto_bot.init()
while True:
start = time.time()
# 调用后台截取屏幕,更新缓存图片
auto_bot.update_img()
mid = time.time()
print("updateimg cost: {}ms".format(mid - start))
# 屏幕颜色获取
x, y = 100, 200
pixel = auto_bot.get_pixels(x, y)
print('screen ({},{}) color_rgba:{}'.format(x, y, pixel))
# 全屏查找相似颜色
x, y = auto_bot.find_color("#FFFFFF", 0.9)
print(x, y)
# 指定区域查找相似颜色
x, y = auto_bot.find_color_area(50, 100, 100, 200, "#FFFFFF", 0.9)
print(x, y)
# 按键示例
key_press_example()
# 屏幕点击示例
touch_example()
# 文字输入需激活输入框
# text_example()
end = time.time()
print("cost time: {}ms".format(end - start))
# 暂停一会儿
# time.sleep(random.uniform(3, 5))
if __name__ == '__main__':
main()