Python Script for Mouse Accuracy Game
Here's a Python script that uses PyAutoGUI and OpenCV to automatically click on the red circles in the mouse accuracy game:
import pyautogui
import numpy as np
import cv2
import time
import mss
# Configuration
RED_COLOR_LOWER = [150, 0, 0] # Lower bound for red color in BGR format
RED_COLOR_UPPER = [255, 100, 100] # Upper bound for red color in BGR format
CLICK_DELAY = 0.1 # Delay between clicks in seconds
GAME_REGION = None # Set to (left, top, width, height) if you want to limit the search area
def find_red_circles():
with mss.mss() as sct:
# Capture screen
if GAME_REGION:
monitor = GAME_REGION
else:
monitor = {"top": 0, "left": 0, "width": pyautogui.size().width, "height": pyautogui.size().height}
img = np.array(sct.grab(monitor))
# Convert to BGR format (OpenCV uses BGR by default)
img_bgr = cv2.cvtColor(img, cv2.COLOR_BGRA2BGR)
# Create mask for red color
lower_red = np.array(RED_COLOR_LOWER, dtype="uint8")
upper_red = np.array(RED_COLOR_UPPER, dtype="uint8")
mask = cv2.inRange(img_bgr, lower_red, upper_red)
# Find contours in the mask
contours, _ = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
# Filter small contours (noise) and get their centers
centers = []
for contour in contours:
if cv2.contourArea(contour) > 10: # Minimum area threshold
M = cv2.moments(contour)
if M["m00"] != 0:
cX = int(M["m10"] / M["m00"])
cY = int(M["m01"] / M["m00"])
centers.append((cX + monitor["left"], cY + monitor["top"])) # Convert to screen coordinates
return centers
def main():
print("Starting in 3 seconds... Move your mouse to the game area!")
time.sleep(3)
print("Running... Press Ctrl+C to stop.")
try:
while True:
centers = find_red_circles()
if centers:
# Click on each detected red circle
for x, y in centers:
pyautogui.moveTo(x, y, duration=0.1)
pyautogui.click()
time.sleep(CLICK_DELAY)
time.sleep(0.1) # Small delay to prevent high CPU usage
except KeyboardInterrupt:
print("\nScript stopped by user.")
if __name__ == "__main__":
# Install required packages if not already installed
try:
import pyautogui
import cv2
import mss
except ImportError:
print("Installing required packages...")
import subprocess
import sys
subprocess.check_call([sys.executable, "-m", "pip", "install", "pyautogui", "opencv-python", "mss"])
main()
How to Use This Script:
-
Install the required packages if you don't have them:
pip install pyautogui opencv-python mss
-
Open the mouse accuracy game in your browser and make sure it's visible on your screen.
-
Run the script. It will start after a 3-second delay.
-
The script will:
- Continuously scan your screen for red circles
- Move the mouse to each detected red circle
- Click on it
- Repeat until you stop it with Ctrl+C
Notes:
- The script uses color detection to find red circles, so it should work with the game settings you specified.
- You can adjust the
RED_COLOR_LOWER and RED_COLOR_UPPER values if the script isn't detecting the circles correctly.
- For better performance, you can define the
GAME_REGION to limit the area where the script searches for circles (format: (left, top, width, height)).
- The script includes a small delay between clicks to prevent it from being too obvious.
Remember that using automation scripts on games may violate their terms of service, so use this for educational purposes only.