PyAutoGUI-すべてのGUIを自動化
インストールコマンド:
pipインストールpyautogui
1はじめに
1.1目的
PyAutoGUIは純粋なPython GUI自動化ツールで、プログラムを使用してマウスとキーボードの操作を自動的に制御することを目的としています。複数のプラットフォーム(Windows、OS X、Linux)をサポートしています。pipを使用して、Githubにソースコードをインストールできます。
次のコードは、マウスを画面の中央に移動します。
import pyautogui
screenWidth, screenHeight = pyautogui.size()
pyautogui.moveTo(screenWidth / 2, screenHeight / 2)
PyAutoGUIは、マウスの動き、クリック、ドラッグ、キーボードのキー入力、押し続ける操作、マウス+キーボードのホットキーを同時に押し続ける動作をシミュレートでき、手を動かすことができると言えます。
pyautogui基本操作例
import pyautogio
# 获取当前屏幕分辨率
screenWidth, screenHeight = pyautogui.size()
# 获取当前鼠标位置
currentMouseX, currentMouseY = pyautogui.position()
# 鼠标移动坐标为100, 100位置 绝对移动
pyautogui.moveTo(100, 100)
# 鼠标左击
pyautogui.click()
# 鼠标向下移动 相对移动
pyautogui.moveRel(None, 10)
# 鼠标双击
pyautogui.doubleClick()
# 用缓动/渐变函数让鼠标2秒后移动到(500, 500)位置
# use tweening/easing function to move mouse over 2 seconds.
pyautogui.moveTo(500, 500, duration=2, tween=pyautogui.easeInOutQuad)
# 在每次输入之间暂停0.25秒
pyautogui.typewrite('Hello world!', interval=0.25)
# 键盘点击esc
pyautogui.press('esc')
# 按住shift键
pyautogui.keyDown('shift')
pyautogui.press(['left', 'left', 'left', 'left', 'left', 'left'])
# 放开shift键
pyautogui.keyUp('shift')
pyautogui.hotkey('ctrl', 'c')
PyAutoGUIキーボードテーブル:
「Enter」(または「Return」または「\ n」) |
キャリッジリターン |
'ESC' |
ESC |
「shifttleft」、「shiftright」 |
左右のSHIFTキー |
「altleft」、「altright」 |
左右のAltキー |
「ctrlleft」、「ctrlright」 |
左右のCTRLキー |
'タブ'( '\ t') |
TAB键 |
「バックスペース」、「削除」 |
バックスペース、削除键 |
「pageup」、「pagedown」 |
PAGE UPおよびPAGE DOWN键 |
「家」、「終わり」 |
HOMEおよびENDキー |
'上下左右' |
矢印キー |
'f1'、 'f2'、 'f3' ... |
F1…….F12キー |
「volumemute」、「volumedown」、「volumeup」 |
一部のキーボードは |
「一時停止」 |
ポーズキー |
「capslock」、「numlock」、「scrolllock」 |
CAPS LOCK、NUM LOCK、およびSCROLL LOCKキー |
'インサート' |
INSまたはINSERTキー |
「printscreen」 |
PRTSCまたはPRINT SCREENキー |
「winleft」、「winright」 |
勝利キー |
'コマンド' |
Mac OS Xコマンドキー |
ドキュメンテーション:
https://muxuezi.github.io/posts/doc-pyautogui.html
http://pyautogui.readthedocs.io/en/latest/introduction.html
http://blog.csdn.net/ibiao/article/details/54406803
http://www.chenxm.cc/post/633.html