IT/Python
Python PyAutoGUI Control
Bigtrue
2021. 1. 14. 08:41
Python PyAutoGUI Control
Python PyAutoGUI install
- pip install pyautogui
Python PyAutoGUI Keyboard and Mousee Control
import pyautogui
# Move the mouse to the x, y coordinates 100, 150.
pyautogui.moveTo(100, 150)
# Click the mouse at its current location.
pyautogui.click()
# Double click the mouse at the
pyautogui.doubleClick()
# Click the mouse at the x, y coordinates 200, 220.
pyautogui.click(200, 220)
# Move mouse 10 pixels down, that is, move the mouse relative to its current position.
pyautogui.move(None, 10)
# Type with quarter-second pause in between each key.
pyautogui.write('Hello world!', interval=0.25)
# Simulate pressing the Escape key.
pyautogui.press('esc')
pyautogui.keyDown('shift')
pyautogui.write(['left', 'left', 'left', 'left', 'left', 'left'])
pyautogui.keyUp('shift')
pyautogui.hotkey('ctrl', 'c')
Python PyAutoGUI Display Message Boxes
import pyautogui
pyautogui.alert('This is an alert box.')
pyautogui.confirm('Shall I proceed?')
pyautogui.confirm('Enter option.', buttons=['A', 'B', 'C'])
pyautogui.prompt('What is your name?')
pyautogui.password('Enter password (text will be hidden)')
Python PyAutoGUI Screenshot Functions
import pyautogui
im1 = pyautogui.screenshot()
im1.save('my_screenshot.png')
im2 = pyautogui.screenshot('my_screenshot2.png')
Python 응용프로그램 실행
import os
## 응용프로그램 실행
os.startfile("C:\path\filename.exe")