简单的颜色检测和鼠标按下脚本
我正在尝试编写一个脚本来检测特定屏幕位置上的颜色(颜色以随机时间间隔出现)。当检测到颜色时,它应该在光标位置上执行左键单击。有人可以帮我吗我卡住了
import pyautogui
import keyboard
# Define the coordinates of the screen position to monitor
x = 500
y = 500
# Define the RGB values for the color to detect
target_color = (255, 165, 0)
# Function to check if the 'p' key is pressed
def check_start_key():
return keyboard.is_pressed('p')
# Wait for the start key ('p') to be pressed
while not check_start_key():
pass
while True:
# Check if the target color is detected at the specified position
if pyautogui.pixel(x, y) == target_color:
# Get the current cursor position
cursor_x, cursor_y = pyautogui.position()
# Perform a left mouse click at the cursor location
pyautogui.click(cursor_x, cursor_y)