[英]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))
這是我的代碼,但我不明白為什么程序不單擊或將鼠標移動到所需位置
您正在使用x1
和y1
而不在您的代碼中定義它。
如果你想使用x
和y
如果你只是在for
子句中定義它,
您應該使用x
, y
而不是x1
和y1
。
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.