提问者:小点点

Pyautogui:我必须手动移动鼠标,Pyautogui才能单击


注意:我的问题不是它没有点击,我的问题是它只在我手动移动鼠标时点击一次

我正在使用python库“pyautogui”,当我运行这样的代码时:

import pyautogui
pyautogui.FAILSAFE = True
while True:
    cash = pyautogui.locateOnScreen('cash.png',confidence=0.8)
    if cash != None:
        pyautogui.click(cash)

它会找到它要找的东西,但在我手动移动鼠标之前不会单击它。

每次我尝试pyautogui时都会发生这种情况。


共3个答案

匿名用户

Pyautogui似乎发送了太多鼠标无法处理的请求,因此通过增加时间来降低速度。睡眠(1)起了作用。

我不知道是否有其他人有这个问题,但我很高兴它被修复!

匿名用户

这可能是因为您没有在单击()函数中插入坐标。如果你不插入坐标,python将点击鼠标指针的位置。如果你像“单击(12,35)”一样插入坐标,那么python将单击你输入的特定坐标。您可以通过任何图像编辑器(如油漆)获得屏幕的坐标

匿名用户

>>> import pyautogui

>>> screenWidth, screenHeight = pyautogui.size() # Get the size of the primary monitor.

>>> currentMouseX, currentMouseY = pyautogui.position() # Get the XY position of the mouse.

>>> pyautogui.moveTo(100, 150) # Move the mouse to XY coordinates.

>>> pyautogui.click()          # Click the mouse.
>>> pyautogui.click(100, 200)  # Move the mouse to XY coordinates and click it.
>>> pyautogui.click('button.png') # Find where button.png appears on the screen and click it.

>>> pyautogui.move(0, 10)      # Move mouse 10 pixels down from its current position.
>>> pyautogui.doubleClick()    # Double click the mouse.
>>> pyautogui.moveTo(500, 500, duration=2, tween=pyautogui.easeInOutQuad)  # Use tweening/easing function to move mouse over 2 seconds.

>>> pyautogui.write('Hello world!', interval=0.25)  # type with quarter-second pause in between each key
>>> pyautogui.press('esc')     # Press the Esc key. All key names are in pyautogui.KEY_NAMES

>>> pyautogui.keyDown('shift') # Press the Shift key down and hold it.
>>> pyautogui.press(['left', 'left', 'left', 'left']) # Press the left arrow key 4 times.
>>> pyautogui.keyUp('shift')   # Let go of the Shift key.

>>> pyautogui.hotkey('ctrl', 'c') # Press the Ctrl-C hotkey combination.

>>> pyautogui.alert('This is the message to display.') # Make an alert box appear and pause the program until OK is clicked.

在您的情况下,请使用pyautogui。单击(100200)#将鼠标移动到XY