본문 바로가기
Programming/파이썬

PyAutoGUI

by 기적 2021. 1. 15.

파이썬에서 마우스, 키보드 컨트롤을 하기 위한 모듈

주로 마우스나 키보드 Macro를 만들어 사용할때 사용 하는 모듈이다.

PyAutoGUI에는 몇 가지 기능이 있습니다.

  • 마우스를 이동하고 다른 응용 프로그램의 창을 클릭하거나 입력합니다.
  • 응용 프로그램에 키 입력 보내기 (예 : 양식 작성)
  • 스크린 샷을 찍고 이미지 (예 : 버튼 또는 체크 박스)가 주어지면 화면에서 찾습니다.
  • 응용 프로그램의 창을 찾아 이동, 크기 조정, 최대화, 최소화 또는 닫기 (현재 Windows 전용)
  • GUI 자동화 스크립트가 실행되는 동안 사용자 상호 작용을위한 메시지 상자를 표시합니다.

 

예) pyautogui.readthedocs.io/en/latest/ 참고

import pyautogui

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

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

>>> 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(0, 10)      # Move mouse 10 pixels down from 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

>>> pyautogui.keyDown('shift') # Press the Shift key down and hold it.
>>> pyautogui.press(['left', 'left', 'left', 'left']) # Press the left arrow key 4 times.
>>> pyautogui.keyUp('shift')   # Let go of the Shift key.

>>> 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.​

 

댓글