is this a decent script for such of an request
Archived 2 years ago
U
Coke
i need a script that if it sees a green color in one spot using x/y coordinates and then when it sees it it clicks 2 different "website buttons" that you can find with using y/z coordinates.
and the same script that when it sees red or the green disappears it clicks 2 different buttons
import pyautogui
def detect_and_click_buttons():
# Define the color thresholds for green and red
green_threshold = (50, 200, 50) # Adjust the values for your desired green color
red_threshold = (200, 50, 50) # Adjust the values for your desired red color
# Define the coordinates of the color detection spot
color_spot_x = 100 # Replace with the X-coordinate of the spot
color_spot_y = 200 # Replace with the Y-coordinate of the spot
# Define the coordinates of the first and second buttons
button_1_x = 300 # Replace with the X-coordinate of the first button
button_1_y = 400 # Replace with the Y-coordinate of the first button
button_2_x = 500 # Replace with the X-coordinate of the second button
button_2_y = 600 # Replace with the Y-coordinate of the second button
while True:
# Get the current screen pixel color at the color detection spot
pixel_color = pyautogui.pixel(color_spot_x, color_spot_y)
if pixel_color == green_threshold:
# Perform button clicks when the desired green color is detected
pyautogui.click(button_1_x, button_1_y)
pyautogui.click(button_2_x, button_2_y)
elif pixel_color == red_threshold or pixel_color != green_threshold:
# Perform button clicks when red is detected or the green color disappears
pyautogui.click(button_1_x, button_1_y)
pyautogui.click(button_2_x, button_2_y)
detect_and_click_buttons()
