Skip to content
조회 수 5257 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

파이썬 pyautogui 자주쓰는 이미지 서치 def 지정하기


 

 
#https://goodthings4me.tistory.com/491
import pyautogui
import pywinauto
import pyperclip
import time
import cv2 #open-cv2-python
 
#---
 
#캡쳐한 이미지가 화면에 여러개 일때 n번째
#원하는 이미지의 위치들을 리스트에 저장해놓고 for문으로 하나씩 꺼내어 쓰는 개념
def m_imgs(fname):
    for i in pyautogui.locateAllOnScreen(fname):
        pyautogui.click(i, duration=0.25)
        print(i)
 
#동일한 이미지 중 n번째 이미지 클릭
def m_img(fname,cntnum):
    cnt=0
    for i in pyautogui.locateAllOnScreen(fname):
        if cnt is cntnum:
            pyautogui.click(i, duration=0.25)
            print(i)
        cnt=cnt+1

#범위 안에서만 캡처한 이미지를 찾고 싶을 때
def m_imgs(fname,x1,y1,x2,y2):
    img_capture = pyautogui.locateOnScreen(fname, region=(x1,y1,x2,y2))
    pyautogui.moveTo(img_capture)
    start = time.time()  # 시작 시간 저장
    print("코드 실행 시간 :", time.time() - start) # 현재시각 - 시작시각 = 실행 시간
 
# 동일 형상 중에 특정번째만 동작하기
def Dupclick(num,fname):
    for idx, i in enumerate(pyautogui.locateAllOnScreen(fname), start=1):
        if idx == num: # num번쨰 등장하는 형상에만 동작 *참고 : start=1
            pyautogui.click(i)
 
#검색된 이미지의 x,y좌표를 구해서 img_p 변수로 리턴합니다.
def imgif(url):
    img_p = pyautogui.locateOnScreen(url)
    print('이미지 xy좌표:',img_p)
    return img_p
 
#검색된 이미지를 클릭합니다.
def imgclick(url):
    img_xy = pyautogui.locateOnScreen(url)
    time.sleep(random.randrange(1,3))
    pyautogui.click(img_xy)
    print('이미지 클릭:',img_xy)
   
#검색된 이미지를 xy좌표를 클릭합니다.
def xyclick(url):
    img_xy = pyautogui.locateOnScreen(url)
    time.sleep(random.randrange(1,3))
    pyautogui.moveTo(img_xy)
    time.sleep(random.randrange(1,3))
    pyautogui.click()
    print('xy좌표 클릭:',img_xy)    
    pyautogui.moveTo(100, 200) # x 100, y 200 위치로 바로 이동
 
#상하좌우 범위를 지정한 파일이름으로 저장합니다.
def imgshot(fname,x1,y1,x2,y2):
    img_sc = pyautogui.screenshot(fname, region=(x1,y1,x2,y2))
    time.sleep(random.randrange(1,3))
#---
 
windows = pyautogui.getAllWindows()
 
for window in windows:
    print(window)
   
noactive = pyautogui.getWindowsWithTitle('농업교육포털 - Chrome')[0]
if noactive.isActive == False:
    noactive.activate()
   
#https://agriedu.net/page/client_study_ing#appPage_study_status_ing_online
 
# 아래방향키 9번 누른다.
 
fname="C:/Python/py_code/automouse/img/nongsa/test-0.png"
m_img(fname,1)



 

 

로그인 후 댓글쓰기가 가능합니다.

?

List of Articles
번호 분류 제목 날짜 조회 수
897 컴퓨터잡담 H734GP 공유기 시스템로그 중 >>> Send Offer / Receive Discover / 2023.06.04 51716
896 WindowsTip VBS) FTP.scriptlet and Shell.scriptlet 2013.09.21 48506
895 파이썬 python AttributeError: 'WebDriver' object has no attribute 'find_element_by_css_selector' 해결방법 2023.05.07 47577
894 AutoHotKey AHK) 보안프로그램 등으로 화면복사(Printscreen) 안될때 사용방법 1 12 file 2012.11.21 47166
893 프로세스 pinomate.exe 프로세스 삭제방법 6 2011.02.13 45999
892 WindowsTip VBS) PostMessage or SendMessage to external program 2013.09.21 45965
891 컴퓨터잡담 2023-09-23 서버다운 후 복구완료 secret 2023.09.23 45178
890 컴퓨터잡담 [PHP] 원격지의 이미지 사이즈 구하는 방법 2 2009.08.11 44528
889 AutoHotKey Ahk) 웹페이지 감시결과에 따라 마이피플로 글 전송하기 12 file 2013.01.06 44023
888 컴퓨터잡담 emule 서버리스트 2010.11.10 43048
887 Excel Excel Vba) 셀의 행, 열(column, row) 주소 알아내기 또는 삽입하기 더불어 제어하기 2012.01.05 42974
886 AutoHotKey Autohotkey) 화면보호기(ScreenSaver) On/Off 방법 17 2012.03.16 40675
885 [Docs]스프레드시트 구글 스프레드시트에서 셀값이 특정일에서 현재일과 3일 이내의 범위에 들어오면 이메일을 발송하는 방법 2023.03.26 40553
884 Excel GET.CELL 매크로함수 응용 11 2012.07.16 40176
883 컴퓨터잡담 안드로이드 동영상 재생시 파란색 물음표 박스만 나올때 조치방법 2 file 2013.04.26 39285
882 컴퓨터잡담 URL Encoding 특수문자코드 4 2012.03.30 39076
881 컴퓨터잡담 mysql 날짜타입에 기본값으로 현재시간넣기 1 2009.12.07 38588
880 AutoHotKey ahk) 오토핫키 콤보박스 제어하기 file 2013.10.30 38180
879 컴퓨터잡담 테블릿을 세컨트모니터로??? 2023.04.26 38125
878 WindowsTip 네트워크에 있는 다른 시스템과 ip 주소가 충돌합니다. 1 file 2013.03.29 38112
Board Pagination Prev 1 2 3 4 5 ... 46 Next
/ 46

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소