LoginSignup
41
61

More than 3 years have passed since last update.

Pythonでクリックを自動化した

Last updated at Posted at 2019-10-13

環境準備

Python2.7をダウンロード1
https://www.python.jp/install/windows/install_py2.7.html

記載されている指示に従い
Windows x86-64 MSI installer
をインストール。

こちらの指示に従い、pipでpyautoguiをインストール。
https://qiita.com/hirohiro77/items/78e26a59c2e45a0fe4e3

動作確認も
https://qiita.com/hirohiro77/items/78e26a59c2e45a0fe4e3
に記載の通り、コマンドプロンプトからPythonを呼び出して、一個ずつimportして、まず座標の取得ぐらいをやってみる。

今回の自分の目的では簡単な確認だけで良いので

import pyautogui
a = pyautogui.position()
a

を1つずつ打って、現在のマウスの座標が取得できるかどうか確認する。
確認できたら、Ctrl+Z+EnterでPythonを抜ける。

クリック自動化

下記のコマンドでクリック動作をプログラム上に記載することができる。

import pyautogui
pyautogui.click(x,y) # x,yにはpyautogui.position()で取得した値を自分で入れる

また、クリックとクリックの間に時間開けた方が良い場合には、

import time
time.sleep(w) # wには待ち時間[秒]を入れる

exe化

exe化について全くの初心者だったため、下記を参照。
https://techacademy.jp/magazine/18963

pip install pyinstaller

のコマンドについては、VScode上のターミナルからは実行できず、Windowsのコマンドプロンプトからは実行できた。

pyinstaller ファイル名.py

でexe化に成功。できたファイルは
C:XXX/Python27/Scripts/build/ファイル名/ファイル名.exe
に保存されている。


参考にしました
https://dropoutgs.com/python-operation-auto/
https://pyautogui.readthedocs.io/en/latest/mouse.html#mouse-clicks
https://www.python-izm.com/introduction/execution/
https://techacademy.jp/magazine/18963


  1. Python3でも動くのかどうかはわからない 

41
61
6

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
41
61