pu369com

pyautogui.locateOnScreen在屏幕上查找图片并点击

1.在Win10中任意窗口按下"Win+Shift+S"组合键进入截屏模式 ,截图并保存为 n.png

2.代码:

#encoding=utf-8
import pyautogui
from PIL import Image
import time

time.sleep(3)
left, top, width, height = pyautogui.locateOnScreen(r"n.png")
center = pyautogui.center((left, top, width, height))
pyautogui.click(center)

 小改一下

#encoding=utf-8
import pyautogui
import pyperclip as pc
import time

def C(pic):
    box = pyautogui.locateOnScreen(pic)
    if not(box is None):
        center = pyautogui.center(box)
        pyautogui.click(center)
    else:
        time.sleep(2)
        print("未发现图片,2秒后将继续查找")
        C(pic)
        
def Cxy(pic,a,b):
    box = pyautogui.locateOnScreen(pic)
    if not(box is None):
        center = pyautogui.center(box)
        center1=(center.x+a,center.y+b)
        pyautogui.click(center1)
    else:
        time.sleep(2)
        print("未发现图片,2秒后将继续查找")
        C(pic)

def A():    
    print("请切换到要处理的界面")
    time.sleep(3)
    Cxy("1.png",-30,5)
    C("2.png")
    pc.copy("无脑点击")
    pc.paste()
    pyautogui.hotkey('ctrl', 'v')
    C("3.png")
    C("4.png")
    
for i in range(0,10):
    A()
print("程序结束")

   

  

 模糊查找、灰度、指定范围、多图定位,locateAllOnScreen  具体参考 https://www.bbsmax.com/A/nAJvQYbGzr/

 

posted on 2023-03-10 17:14  pu369com  阅读(1825)  评论(0)    收藏  举报

导航