检查屏幕上像素的颜色值

Check color value of pixel on screen

我正在制作一个机器人,如果鼠标不是特定颜色,它会自动点击。我拥有从定位到点击的一切,但我不知道如何检查鼠标悬停的像素是否为特定颜色。我目前使用 mousekeyboard,google 没有给出适合我情况的结果。

它也不是图像,而是实时显示在屏幕上。

它应该看起来像这样:

colorUnderMouse = getColorUnderMouse()
if colorUnderMouse == "FF00FF":
  mouse.click('left')
else:
  mouse.move(10, 0, absolute=False, duration=0)

您可以使用 pyautogui:

import pyautogui

def getColorUnderMouse():
    x, y= pyautogui.position()
    pixel = pyautogui.screenshot(
        region=(
            x, y, 1, 1
        )
    )
    return pixel.getcolors()