Created
September 5, 2018 14:06
pyautogui_locate_operation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyautogui as pa | |
# ディスプレイのサイズを取得する | |
max_x,max_y = pa.size() # (1920, 1080) タプルで出力される | |
max_x # 1920 | |
max_y # 1080 | |
# マウスの座標を取得する | |
p_x,p_y = pa.position() # (675, 766) タプルで出力される | |
p_x # 675 | |
p_y # 766 | |
# 指定画像と同一の画像をディスプレイ内から認識し、座標を取得する | |
p_x,p_y = pa.locateCenterOnScreen("c:\\MyPythonScripts/img/pa_search_img.png") # (264, 120) 画像をあらかじめ用意しておく。 | |
p_x # 264 注意:ブラウザの表示倍率を変えてしまうと、違う画像になってしまうので認識しない。 | |
p_y # 120 | |
pos_x,pos_y,size_x,size_y = pa.locateOnScreen("target.png") #それぞれの要素をとる | |
pos = pa.locateOnScreen("target.png") #配列に格納してとる | |
pos_x,pos_y = pa.center("target.png") #画像の中心座標を取る | |
pa.locateOnScreen("someButton.png", region=(0,0, 300, 400)) # region=サーチ範囲 | |
pa.locateOnScreen("button_img.png", grayscale=True, region=(0,0, 300, 400) )# グレースケールで画像を認識する | |
pa.locateOnScreen("button_img.png", grayscale=True,tolerance=10 ,region=(0,0, 300, 400)) #マッチ誤差(tolerance)[0-100%]を取得する | |
# スクリーンショット | |
pa.screenshot("c:\\MyPythonScripts/img/screenshot_img.png") # 全体 | |
pa.screenshot(region=(1,1, 640, 480))# 矩形範囲指定 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment