官網

https://pyautogui.readthedocs.io/en/latest/

Welcome to PyAutoGUI's documentation! - PyAutoGUI documentation

官網範例

>>> import pyautogui

>>> screenWidth, screenHeight = pyautogui.size() # Get the size of the primary monitor.
>>> screenWidth, screenHeight
(2560, 1440)

>>> currentMouseX, currentMouseY = pyautogui.position() # Get the XY position of the mouse.
>>> currentMouseX, currentMouseY
(1314, 345)

>>> pyautogui.moveTo(100, 150) # Move the mouse to XY coordinates.

>>> pyautogui.click()          # Click the mouse.
>>> pyautogui.click(100, 200)  # Move the mouse to XY coordinates and click it.
>>> pyautogui.click('button.png') # Find where button.png appears on the screen and click it.

>>> pyautogui.move(400, 0)      # Move the mouse 400 pixels to the right of its current position.
>>> pyautogui.doubleClick()     # Double click the mouse.
>>> pyautogui.moveTo(500, 500, duration=2, tween=pyautogui.easeInOutQuad)  # Use tweening/easing function to move mouse over 2 seconds.

>>> pyautogui.write('Hello world!', interval=0.25)  # type with quarter-second pause in between each key
>>> pyautogui.press('esc')     # Press the Esc key. All key names are in pyautogui.KEY_NAMES

>>> with pyautogui.hold('shift'):  # Press the Shift key down and hold it.
        pyautogui.press(['left', 'left', 'left', 'left'])  # Press the left arrow key 4 times.
>>> # Shift key is released automatically.

>>> pyautogui.hotkey('ctrl', 'c') # Press the Ctrl-C hotkey combination.

>>> pyautogui.alert('This is the message to display.') # Make an alert box appear and pause the program until OK is clicked.

如何在mac安裝PyAutoGUI套件

因為youtube上傳影片後預設會是草稿模式,其他選項可以用整批更新的方式去做,只有瀏覽權限無法在草稿模式使用,所以就想用python利用自動化的滑鼠鍵盤工具來做這件事,今天先講安裝,及如何確認是否有安裝成功。

pip install PyAutoGUI
python --version 查看python版本

pip list 查看已安裝套件
import pyautogui
screenWidth, screenHeight = pyautogui.size(). --取得目前的螢幕大小

https://youtu.be/hGXC8sZDwBY

如何透過PyAutoGUI套件移動到螢幕的某一個位置

要利用PyAutoGUI去滑鼠移動到螢幕某一個位置時,可以使用moveTo或是move來達到您要的效果。

import pyautogui
pyautogui.moveTo(100,150,duration=1) #移動滑游標到螢幕的x,y
pyautogui.move(100,0)#在原本的位置往右移動100px
pyautogui.move(0,100,duration=1)#在原本的位置往下移動100px

https://youtu.be/hQb8Nv7-A-U