LoginSignup
0
1

More than 5 years have passed since last update.

pyautoguiでクリックマクロを作りたい(願望)

Posted at

完全に個人用のメモとして:yum:

今回書いたコードは以下

jidou.py
#!/usr/bin/python

import pyautogui as pg
import time as ti
import random as rm


def syutuxy():
    x,y=pg.locateCenterOnScreen("syutu.png")
    rx=rm.randint(-39,21)
    ry=rm.randint(-39,26)
    x=x+rx
    y=y+ry
    return x,y


ti.sleep(1)
pg.PAUSE=1.0

x,y=syutuxy()

if x != None and y != None:
    pg.click(x,y,button="left",duration=0.5)
else:
    print("nooo")

予め用意しておいた画像と合致する座標を探してくれる。
今回はランダム要素を含めて座標を抽出。

とりあえずライブラリの動作は確認できた。
用意する画像はmacの「shift + command + 4」で用意すると良い。
ランダム要素はボタンごとに異なるので、しっかり元々の中心を取れるようにスクショしよう。
 →あとはちまちまランダムの範囲指定を…


次回は画像フォルダの階層化と、各ボタン画像を生成しようかしら:zzz:

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1