-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
38 lines (32 loc) · 1.24 KB
/
main.py
File metadata and controls
38 lines (32 loc) · 1.24 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
import pyautogui
from PIL import ImageGrab
import time
TARGET_COLOR = (75, 219, 106)
CLICK_DELAY_MS = 1
def get_mouse_color():
x, y = pyautogui.position()
screen = ImageGrab.grab()
screen_width, screen_height = screen.size
if 0 <= x < screen_width and 0 <= y < screen_height:
return screen.getpixel((x, y)), (x, y)
else:
return None, (x, y)
def main():
click_delay_seconds = CLICK_DELAY_MS / 1000.0
print(f"Move your mouse. Program will wait {CLICK_DELAY_MS} ms before clicking when color {TARGET_COLOR} is detected.")
print("Press Ctrl+C to stop.")
try:
while True:
color, position = get_mouse_color()
if color is not None:
if color == TARGET_COLOR:
print(f"Detected color {TARGET_COLOR} at {position}. Waiting {CLICK_DELAY_MS} ms before clicking...")
time.sleep(click_delay_seconds)
pyautogui.click(position)
print(f"Clicked at {position}.")
else:
print(f"Mouse out of bounds at position {position}.")
except KeyboardInterrupt:
print("\nProgram terminated.")
if __name__ == "__main__":
main()