python中的win32api.setcursorpos错误

问题描述

Okey,所以我正在制作一个应该扮演aim booster

的“简单”机器人

因此,在一些教程的帮助下,我编写了这段代码

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


#color (255,219,195)
run = False

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

while keyboard.is_pressed('w') == False:
        if keyboard.is_pressed('d') and run == False:
                run = True
        if keyboard.is_pressed('a') and run == True:
                run = False
        if run == True:
                if keyboard.is_pressed('d') and run == False:
                        run = True
                if keyboard.is_pressed('a') and run == True:
                        run = False
                pic = pyautogui.screenshot(region=(570,440,1330-570,975-440))
                width,height = pic.size

                for x in range (0,width,5):
                        for y in range(0,height,5):
                                r,g,b = pic.getpixel((x,y))

                                if r == 255 and g == 219 and b ==195:
                                        clicker(x+570,y+440)
                                        time.sleep(0.1)
                                        print("click")
                                        break

但是在我开始运行代码后大约6分钟,它给了我一个

Traceback (most recent call last):
  File "C:\Users\angel\OneDrive\Escritorio\bot_tutorials\acurrate.py",line 35,in <module>
    clicker(x+570,y+440)
  File "C:\Users\angel\OneDrive\Escritorio\bot_tutorials\acurrate.py",line 13,in clicker
    win32api.SetCursorPos((x,y))
pywintypes.error: (0,'SetCursorPos','No error message is available')

或IOError:屏幕抓取失败

我不知道你是否需要这个,但是我的电脑是1920×1080像素,是一个窗口

预先感谢您

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)