-
Notifications
You must be signed in to change notification settings - Fork 37
/
main__locateAllOnScreen.py
48 lines (35 loc) · 989 Bytes
/
main__locateAllOnScreen.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'ipetrash'
from main import show_test_calc
show_test_calc()
BUTTONS = {
'+': 'buttons/add.png',
'-': 'buttons/sub.png',
'/': 'buttons/div.png',
'*': 'buttons/mul.png',
'=': 'buttons/equal.png',
}
for i in range(10):
BUTTONS[str(i)] = 'buttons/{}.png'.format(i)
cache_pos_button = dict()
# OpenCv -- for performance
# pip install opencv-python
# pip install pyautogui
import pyautogui
expression = '1234 * 222 + 3214 = '
for x in expression:
if x not in BUTTONS:
print('Not found: "{}"'.format(x))
continue
if x in cache_pos_button:
pos_list = cache_pos_button[x]
else:
file_name = BUTTONS[x]
pos_list = [pyautogui.center(pos) for pos in pyautogui.locateAllOnScreen(BUTTONS[x])]
if not pos_list:
continue
cache_pos_button[x] = pos_list
print(x, pos_list)
for pos in pos_list:
pyautogui.click(pos)