You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Python自动点击器中设置截图时跳过指定坐标区域以避免误点击自身

Fixing the Auto-Clicker's Accidental Self-Clicks

I get it—your auto-clicker is accidentally targeting your own character because it’s scanning every pixel on the screen, including the area where your bot’s health bar sits. The solution is simple: we just need to add a check to skip the coordinate range (900,600) to (1000,660) when looking for the enemy color.

Here’s the modified code with the fix implemented:

from pyautogui import *
import pyautogui
import time
import keyboard
import random
import win32api, win32con

def click(x,y):
    win32api.SetCursorPos((x,y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)

color = (0, 255, 32)
while keyboard.is_pressed('q') == False:
    s = pyautogui.screenshot()
    width, height = s.size
    for x in range(0,width,5):
        for y in range(0,height,5):
            # Skip the specified region to avoid clicking your own character
            if 900 <= x <= 1000 and 600 <= y <= 660:
                continue  # Move to the next pixel without checking
            if s.getpixel((x, y)) == color:
                click(x,y)
                pyautogui.keyDown('space')
                pyautogui.keyUp('space')
                time.sleep(0.05)

Breakdown of the fix:

  • We added a conditional check right before verifying the pixel color: if 900 <= x <= 1000 and 600 <= y <= 660:
  • The continue statement tells the loop to skip processing this pixel entirely. This means the code will never check (or click) any pixels within that forbidden rectangle.

If your character’s position shifts slightly and you still get accidental clicks, just adjust the coordinate values in the conditional to match the new area you want to exclude.

内容的提问来源于stack exchange,提问作者LongLifeCode

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 19:47:30