pyautogui 每次点击都会崩溃 [英] pyautogui crashes whenever it clicks

查看:121
本文介绍了pyautogui 每次点击都会崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,每当我调用 pyautogui 来单击它时,它都会执行此操作,然后使程序崩溃.这是程序:

basicly whenever I call pyautogui to click it does it but then crashes the program. here is the program:

import pyautogui
import time
pyautogui.click(650, 200, 10)
print("started")
while 2 == 2:
    x+1
    waittime = random.randrange(35, 40, 1)
    pyautogui.click(600, 680, waittime)
    pyautogui.click(1270, 0, 5)
    if (x % 4) == 0:
        pyautogui.click(600, 550, 4)

当我从命令提示符运行它时,出现此错误

when I run it from the command prompt I get this error

Traceback (most recent call last):
  File "C:\Users\dogja\Desktop\crap\region2\scriptybob\test.py", line 3, in <module>
    pyautogui.click(650, 200, 10)
  File "C:\Users\dogja\AppData\Local\Programs\Python\Python35\lib\site-    packages\pyautogui\__init__.py", line 362, in click
    platformModule._click(x, y, 'left')
  File "C:\Users\dogja\AppData\Local\Programs\Python\Python35\lib\site-    packages\pyautogui\_pyautogui_win.py", line 437, in _click
    _sendMouseEvent(MOUSEEVENTF_LEFTCLICK, x, y)
  File "C:\Users\dogja\AppData\Local\Programs\Python\Python35\lib\site-    packages\pyautogui\_pyautogui_win.py", line 480, in _sendMouseEvent
    raise ctypes.WinError()
OSError: [WinError 127] The specified procedure could not be found.

推荐答案

这个问题可能是由于最新版本的 pyautogui 是为 python 3.4 设计的,而最新版本是 3.5.我发现如果你运行的是 Windows,你可以使用 win32api.要安装它,请在管理员模式下运行命令提示符并 cd 到您的 python 脚本目录并运行以下命令:

The problem may have been being caused by the fact that the latest version of pyautogui was intended for python 3.4 when the latest is 3.5. I found that if you're running Windows, you can use win32api. To install this, run the command prompt in admin mode and cd to your python script directory and run this command:

pip install win32api

这将安装 win32api 及其先决条件.

This will install win32api and its prerequisites.

然后,要为 win32api 制作一个简单的点击包装器,请使用此函数:

Then, to make a simple click wrapper for win32api, use this function:

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

这实际上是将光标移动到某个地方,按下鼠标左键,然后非常快速地释放它.我没有写上面显示的点击片段,但我找不到我首先找到它的地方.对编写该片段的人表示抱歉.

This essentially moves the cursor somewhere, presses the left mouse button down, and releases it very fast. I did not write the click snippet shown above, but I could not find where I found it first. Sorry to whoever wrote that snippet.

这篇关于pyautogui 每次点击都会崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆