-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
64 lines (49 loc) · 1.69 KB
/
helpers.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import win32clipboard
import os
import time
import pyautogui as pag
pag.PAUSE = 0
def findImage(imageUrl: str, confidence: int = 0.90):
try:
x, y = pag.locateCenterOnScreen(
f"{imageUrl}", confidence=confidence, grayscale=True)
except TypeError:
x, y = -1, -1
return (x, y)
def forceFind(imageUrl: str, grayscale: bool = True):
while True:
try:
x, y = pag.locateCenterOnScreen(
f"{imageUrl}", confidence=0.9, grayscale=grayscale)
except TypeError:
continue
return (x, y)
def findImageTimeout(imageUrl: str, timeout: int, region: tuple, grayscale: bool = True):
i = 1
rate = 10
while True:
if i <= (timeout * rate):
try:
t1 = time.time()
if region:
# search in given area
x, y = pag.center(pag.locate(f"{imageUrl}", pag.screenshot(
region=region), confidence=0.9, grayscale=grayscale))
return (x + region[0], y + region[1])
else:
# search center on screen
x, y = pag.locateCenterOnScreen(
f"{imageUrl}", confidence=0.9, grayscale=grayscale)
return (x, y)
except TypeError:
# make every iteration 1s
i += 1
try:
# print((1 / rate) - (time.time() - t1))
time.sleep((1 / rate) - (time.time() - t1))
except:
continue
else:
return (-1, -1)
def clear():
os.system("cls" if os.name == "nt" else "clear")