pyautogui点击它时会崩溃

时间:2016-04-24 14:22:40

标签: python python-3.x pyautogui

基本上,每当我打电话给pyautogui点击它时,它会崩溃程序。这是程序:

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)

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

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.

2 个答案:

答案 0 :(得分:1)

Maybe you are not using the click function in right way. See the function definition:

click(x=None, y=None, clicks=1, interval=0.0, button='left', duration=0.0, tween=, pause=None, _pause=True)

Using pyautogui.click(650, 200, 10) you are saying x=650, y=200 and clicks=10. I guess you want to say pyautogui.click(650, 200, interval=10).

答案 1 :(得分:0)

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

pip install win32api

这将安装win32api及其先决条件 然后为win32api制作一个简单的点击包装使用这个函数:

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)

这实际上将光标移动到某处按下鼠标左键并快速释放它。我没有写上面显示的点击片段,但我找不到我在哪里找到它。抱歉谁写了那个剪辑