PyAutoGUI 中文幫助文檔-快速入門參考

PyAutoGUI 中文幫助文檔-快速入門參考

PyAutoGui是一個跨平臺GUI自動化庫。

PyAutoGUI是一個Python模塊,用於以編程方式控制鼠標和鍵盤。

PyPutoGUI可以從pip工具安裝或從PyPI下載:

https://pypi.python.org/pypi/PyAutoGUI

源代碼可在以下網址獲得:https://github.com/asweigart/pyautogui

--------------------------------------------------------------------

這是使用PyAutoGUI的快速入門參考。 PyAutoGUI是可在Python 2和3上運行的跨平臺GUI自動化模塊。您可以通過PyAutuoGUI控制鼠標和鍵盤以及執行基本圖像識別以自動執行計算機上的任務。

此頁面示例中的所有關鍵字參數都是可選的

PyAutoGUI 中文幫助文檔-快速入門參考

PyAutoGUI 工作於 Windows/Mac/Linux and on Python 2 & 3. 來自於 PyPI with pip install pyautogui.

General Functions

一般功能

PyAutoGUI 中文幫助文檔-快速入門參考

Fail-Safes

失效保護

在每次PyAutoGUI調用後設置2.5秒的暫停:

PyAutoGUI 中文幫助文檔-快速入門參考

當故障安全模式為True時,將鼠標移動到左上角將引發pyautogui.FailSafeException

可以中止你的程序:

PyAutoGUI 中文幫助文檔-快速入門參考

Mouse Functions

鼠標功能

XY座標在屏幕的左上角為0,0原點。 X向右增加,Y向下增加。

PyAutoGUI 中文幫助文檔-快速入門參考

如果duration參數設置為0或未指定,則立即移動。 注意:在Mac上拖動不能立即。

PyAutoGUI 中文幫助文檔-快速入門參考

click()函數默認代表鼠標當前位置的左鍵單擊鼠標一次,但關鍵字參數可以通過參數設置

PyAutoGUI 中文幫助文檔-快速入門參考

button關鍵字參數可以是“left”,“middle”或“right”。代表點擊“左鍵“”中鍵“”右鍵“所有的鼠標點擊都可以用 Click()設置,但是為了方便易於使用,常用點擊函數有以下可選:

PyAutoGUI 中文幫助文檔-快速入門參考

滾動向上是正向滾動,向下滾動是負向滾動:

PyAutoGUI 中文幫助文檔-快速入門參考

可以獨立調用鼠標的按下和放開時間

PyAutoGUI 中文幫助文檔-快速入門參考

Keyboard Functions

鍵盤功能

模擬光標位置按鍵輸入

PyAutoGUI 中文幫助文檔-快速入門參考

也可以傳入一些關鍵命令字列表,包括回車和空格

PyAutoGUI 中文幫助文檔-快速入門參考

鍵盤的功能關鍵字列表定義在 pyAutogui.KEYBOARD_KEYS中。

>>> print(pyautogui.KEYBOARD_KEYS)

['\t', '\n', '\r', ' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '', '?', '@', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 'accept', 'add', 'alt', 'altleft', 'altright', 'apps', 'backspace', 'browserback', 'browserfavorites', 'browserforward', 'browserhome', 'browserrefresh', 'browsersearch', 'browserstop', 'capslock', 'clear', 'convert', 'ctrl', 'ctrlleft', 'ctrlright', 'decimal', 'del', 'delete', 'divide', 'down', 'end', 'enter', 'esc', 'escape', 'execute', 'f1', 'f10', 'f11', 'f12', 'f13', 'f14', 'f15', 'f16', 'f17', 'f18', 'f19', 'f2', 'f20', 'f21', 'f22', 'f23', 'f24', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'final', 'fn', 'hanguel', 'hangul', 'hanja', 'help', 'home', 'insert', 'junja', 'kana', 'kanji', 'launchapp1', 'launchapp2', 'launchmail', 'launchmediaselect', 'left', 'modechange', 'multiply', 'nexttrack', 'nonconvert', 'num0', 'num1', 'num2', 'num3', 'num4', 'num5', 'num6', 'num7', 'num8', 'num9', 'numlock', 'pagedown', 'pageup', 'pause', 'pgdn', 'pgup', 'playpause', 'prevtrack', 'print', 'printscreen', 'prntscrn', 'prtsc', 'prtscr', 'return', 'right', 'scrolllock', 'select', 'separator', 'shift', 'shiftleft', 'shiftright', 'sleep', 'space', 'stop', 'subtract', 'tab', 'up', 'volumedown', 'volumemute', 'volumeup', 'win', 'winleft', 'winright', 'yen', 'command', 'option', 'optionleft', 'optionright']

>>

鍵盤熱鍵如Ctrl-S or Ctrl-Shift-1 可以作為參數被 傳遞給hotkey():

PyAutoGUI 中文幫助文檔-快速入門參考

可以單獨調用單個鍵盤鍵的向下和向上事件:

PyAutoGUI 中文幫助文檔-快速入門參考

Message Box Functions

消息框功能

如果您需要暫停程序直到用戶單擊“確定”,或者想要向用戶顯示某些信息,則消息框函數和JavaScript的函數名稱類似:

PyAutoGUI 中文幫助文檔-快速入門參考

Pyautuogui.alert調用效果

PyAutoGUI 中文幫助文檔-快速入門參考

pyautogui.confirm調用效果

PyAutoGUI 中文幫助文檔-快速入門參考

pyautogui.prompt 運行效果

PyAutoGUI 中文幫助文檔-快速入門參考

如果用戶單擊“取消”,則prompt()函數將返回None。

Screenshot Functions

截圖功能

PyAutoGUI使用Pillow / PIL作為其圖像數據操作基礎庫

在Linux上,您必須運行sudo apt-get install scrot才能使用屏幕截圖功能。

PyAutoGUI 中文幫助文檔-快速入門參考

如果你想點擊屏幕上的某個圖像,可以使用locateOnScreen()在屏幕上找到它。

PyAutoGUI 中文幫助文檔-快速入門參考

The locateAllOnScreen() function 返回所有的圖片位置信

PyAutoGUI 中文幫助文檔-快速入門參考

PyAutoGUI 中文幫助文檔-快速入門參考

locateCenterOnScreen()函數只返回在屏幕上找到圖像的中間的XY座標:

PyAutoGUI 中文幫助文檔-快速入門參考

如果在屏幕上找不到圖像,這些函數將返回None。 注意:定位功能很慢,可能需要一兩秒鐘。

------------------------------------------------------------------------------

相關閱讀:

PyAutoGUI 中文幫助文檔-簡介

PyAutoGUI 中文幫助文檔-安裝


分享到:


相關文章: