为什么我的python程序不单击或移动鼠标?

时间:2019-12-25 23:01:29

标签: python python-3.x

import numpy as np
import pyautogui
import cv2
import time
import sys
from PIL import ImageGrab
import directkeys
import pyscreenshot

cords = [0,1800, 160,1040]
mousepos = pyautogui.position()
print(mousepos)
green = (106,199,0)
low_red = np.array([161,155,84])
high_red = np.array([179,255,255])
screen = ImageGrab.grab(bbox=cords)
screenrgb = screen.convert('RGB')

while True:
    for y in range(screenrgb.height):
        for x in range(screenrgb.width):
            r, g , b = screenrgb.getpixel(x1,y2)
            if (r,g,b) == green:
                pyautogui.click(screenrgb.getpixel(x1,y2))

这是我的代码,但是我看不到为什么程序没有单击鼠标或将鼠标移到所需位置

1 个答案:

答案 0 :(得分:0)

您正在使用x1y1而不在代码中对其进行定义。

如果您想使用xy(如果您刚刚在for子句中定义了它,

您应该使用xy而不是x1y1

import numpy as np
import pyautogui
import cv2
import time
import sys
from PIL import ImageGrab
import directkeys
import pyscreenshot

cords = [0,1800, 160,1040]
mousepos = pyautogui.position()
print(mousepos)
green = (106,199,0)
low_red = np.array([161,155,84])
high_red = np.array([179,255,255])
screen = ImageGrab.grab(bbox=cords)
screenrgb = screen.convert('RGB')

while True:
    for y in range(screenrgb.height):
        for x in range(screenrgb.width):
            r, g , b = screenrgb.getpixel(x,y)
            if (r,g,b) == green:
                pyautogui.click(screenrgb.getpixel(x,y))