Untitled
unknown
plain_text
4 months ago
1.9 kB
5
Indexable
import pyautogui import time import mss import numpy as np import keyboard # For activation hotkey # Function to get the color of the pixel under the cursor def get_pixel_color(x, y): with mss.mss() as sct: monitor = {"top": y, "left": x, "width": 1, "height": 1} img = np.array(sct.grab(monitor)) return tuple(img[0, 0, :3]) # Main function with activation key def auto_click_on_color_change(): previous_color = None active = False # Control whether clicking is active print("Press Ctrl + Shift + A to activate or deactivate auto-clicking.") try: while True: # Check for the activation/deactivation hotkey if keyboard.is_pressed("ctrl+shift+a"): active = not active if active: print("Auto-clicking activated!") # Get the initial color under the cursor x, y = pyautogui.position() previous_color = get_pixel_color(x, y) else: print("Auto-clicking deactivated!") time.sleep(0.5) # Short delay to prevent multiple toggles # Only proceed if auto-clicking is active if active: # Continuously get the current position and color x, y = pyautogui.position() current_color = get_pixel_color(x, y) # Compare the color to detect changes if current_color != previous_color: pyautogui.click() # Left-click print(f"Color change detected. Clicked at ({x}, {y}).") # Update previous color for the next loop previous_color = current_color time.sleep(0.01) # Short delay for fast response except KeyboardInterrupt: print("Script stopped by user.") # Run the function auto_click_on_color_change()
Editor is loading...
Leave a Comment