티스토리 뷰

위 화면에서 '항구'아래 버튼을 클릭 하려고 합니다.

 

이런식으로 버튼의 가운데 부분의 스샷을 떠줍니다.

 

import pyautogui as pg
def screen_shot(x_loc, y_loc, x_size, y_size, filename='departure.png'):
    pg.screenshot(filename, region=(x_loc, y_loc, x_size,y_size))
    print('take screen shot')

if __name__ == '__main__':
    screen_shot(2520, 1191, 40, 25)

위 코드를 이용하면 2520, 1191위치에서 40*25만한 크기의 스샷을 departure.png로 떠줍니다.

 

x, y좌표는 아래 코드로 알 수 있습니다.

import pyautogui as pg

print(pg.position())

 

 

import pyautogui as pg
from time import sleep
import glob
from dho.scr_shot import screen_shot
import win32api, win32con
pg.getWindowsWithTitle("대항해시대 온라인")[0].activate()

def click(x, y):
    print(type(x))
    win32api.SetCursorPos((x ,y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
    sleep(0.1)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)

found = False
while not found:
    fileList = glob.glob('./' + "*.png")
    if len(fileList) == 0:
        screen_shot(f'departure{len(fileList) + 1}.png')
    for fnm in fileList:
        print(fnm)
        b_dep = pg.locateOnScreen(fnm, grayscale=True, confidence=0.9)
        if b_dep != None:
            print('can search', b_dep, type(b_dep.left))
            c = pg.center(b_dep)
            print(c)
            sleep(0.5)
            click(int(c.x), int(c.y))
            print(pg.position())
            found = True
            break
        else:
            print('cannot search')

 

win32api가 없으면 게임 화면으로 마우스 커서가 안들어갑니다.

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함