-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontinue_v2.py
90 lines (78 loc) · 3.5 KB
/
continue_v2.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
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
import Quartz
import pyautogui
import time
import pygetwindow as gw
import os
def get_window_list():
window_list = []
window_info_list = Quartz.CGWindowListCopyWindowInfo(Quartz.kCGWindowListOptionOnScreenOnly, Quartz.kCGNullWindowID)
for window_info in window_info_list:
#print(window_info) # Print each window's information
window_list.append(window_info)
return window_list
def get_window_with_title(title):
for window in get_window_list():
window_title = window.get('kCGWindowOwnerName', '').lower() # Convert to lowercase for case-insensitive comparison
if title.lower() in window_title: # Check if the title is contained within the window title
return window
return None
def similar_colors(col1, col2, tolerance):
return all(abs(c1 - c2) <= tolerance for c1, c2 in zip(col1, col2))
def click_color_in_window(window_title, target_color, color_tolerance):
window = get_window_with_title(window_title)
#print("Retrieved window:", window)
if window:
print(f"Found window: {window_title}")
window_bounds = window['kCGWindowBounds']
center_x = int(window_bounds['X']) + int(window_bounds['Width']) // 2
x = center_x - 50
y = int(window_bounds['Y'] + 150)
width = 100
height = int(window_bounds['Height'] - 150)
print(f"Window position and size: x={x}, y={y}, width={width}, height={height}")
print(f"Target color: {target_color}")
# Take a screenshot of the window
screenshot = pyautogui.screenshot(region=(x, y, width, height))
screenshot_dir = './data'
os.makedirs(screenshot_dir, exist_ok=True)
# Save the screenshot
screenshot_path = os.path.join(screenshot_dir, 'screenshot.png')
screenshot.save(screenshot_path)
print("Screenshot taken")
# Search for the color with tolerance
color_found = False
for i in range(screenshot.width):
for j in range(screenshot.height):
current_color = screenshot.getpixel((i, j))
if similar_colors(current_color, target_color, color_tolerance):
color_found = True
# Save current mouse position
original_mouse_position = pyautogui.position()
# Click on the color
click_x = x + i
click_y = y + j
pyautogui.click(click_x, click_y)
pyautogui.click(click_x, click_y)
print(f"Clicked at: x={click_x}, y={click_y}")
# Return mouse to original position
pyautogui.moveTo(original_mouse_position)
pyautogui.click()
print(f"Clicked at original position: {original_mouse_position}")
break
if color_found:
break
if not color_found:
print("Target color not found in the window.")
else:
print("No window with the specified title found.")
# Replace 'BlueStacks' with the title of the window you're looking for
window_title = "BlueStacks"
# Define the color you want to find (RGB format) and the tolerance
target_color = (66,144,188) # Replace with your target color
color_tolerance = 5 # Define how much the color can vary
while True:
#windows = gw.getAllTitles()
#for window in windows:
# print(window)
click_color_in_window(window_title, target_color, color_tolerance)
time.sleep(10) # Wait