簡體   English   中英

為什么我的python程序不點擊或移動鼠標?

[英]Why doesn't my python program click or move the mouse?

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))

這是我的代碼,但我不明白為什么程序不單擊或將鼠標移動到所需位置

您正在使用x1y1而不在您的代碼中定義它。

如果你想使用xy如果你只是在for子句中定義它,

您應該使用x , y而不是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))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM