我尝试使用pyautogui
在屏幕上定位Spotify的暂停按钮,只是为了开发我的python知识。我运行下面的脚本,并保存了暂停按钮的截图,但鼠标移动到屏幕的右下角,距离按钮所在的位置有几英里远。
import pyautogui
input("Move to target button") #move mouse to pause button
target = pyautogui.position()
local = pyautogui.locateCenterOnScreen("spotify.png", confidence=0.9, grayscale=False)#spotify.png is a screenshot of the pause button
pyautogui.moveTo(local)
print(f"Found: {local}")
print(f"Target: {target}")
#sloppy but wanted to ensure the xy coordinates were correct
x = list(local)
x.append(100)
x.append(100)
im = pyautogui.screenshot('test.png', region=x)
输出示例:
Move to target button
Found: Point(x=1487, y=780)
Target: Point(x=746, y=392)
屏幕尺寸为1440 x 900
在鼠标指向的坐标处没有匹配的图像,但从屏幕截图看,似乎找到了一个?如何修复此问题,使鼠标指向暂停按钮,而不是屏幕右下角?
1条答案
按热度按时间9fkzdhlc1#
import pyautogui导入时间