본문 바로가기

AI/Python Module

PyAutoGUI #파이썬 마우스 키보드 이벤트 제어

https://pyautogui.readthedocs.io/en/latest/keyboard.html#the-hotkey-function

 

Keyboard Control Functions — PyAutoGUI documentation

The write() Function The primary keyboard function is write(). This function will type the characters in the string that is passed. To add a delay interval in between pressing each character key, pass an int or float for the interval keyword argument. For

pyautogui.readthedocs.io


 

예시 코드

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

 

This example drags the mouse in a square spiral shape in MS Paint (or any graphics drawing program):

>>> distance = 200
>>> while distance > 0:
        pyautogui.drag(distance, 0, duration=0.5)   # move right
        distance -= 5
        pyautogui.drag(0, distance, duration=0.5)   # move down
        pyautogui.drag(-distance, 0, duration=0.5)  # move left
        distance -= 5
        pyautogui.drag(0, -distance, duration=0.5)  # move up

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

 

반응형

'AI > Python Module' 카테고리의 다른 글

Python #eunjeon, mecab 모듈 설치  (0) 2021.10.21
Python #KoNLPy  (0) 2021.10.19
Python #PyInstaller  (0) 2021.09.12
Module #matplotlib, #urllib, #BeautifulSoup  (0) 2021.07.26
Module #sklearn  (0) 2021.07.26