使用键盘库时,找到屏幕上出现的循环坐标,用pyautogui鼠标左键点击

问题描述 投票:0回答:1

在这个问题中,keyboard.press("tab"),一个圆圈出现在我正在处理的应用程序中。然后我想找到这个圆的坐标并用鼠标左键单击,但我的代码不起作用。我哪里会犯错。

import pyautogui
import time
import keyboard

def monsterclick():
    keyboard.press("tab")
    x, y = pyautogui.position("tab")

while True:
      monsterclick()
      break
python oop keyboard pyautogui
1个回答
0
投票

使用

pyautogui.position
您正在保存当前光标的 x 和 y,您永远不会在屏幕上找到圆圈。您可以使用
pyautogui.click('circle.png')
定位并单击您作为参数提供的图像:

import pyautogui
import time
import keyboard

def monsterclick():
    keyboard.press("tab")
    # This will locate and click the circle. If the circle is not found it will return none
    x, y = pyautogui.click('circle.png')

while True:
      monsterclick()
      break
© www.soinside.com 2019 - 2024. All rights reserved.