Installation code:
pip install pyautogui
1. Introduction
1.1 Purpose
PyAutoGUI is a pure Python GUI automation tool whose purpose is to automatically control mouse and keyboard operations with programs, multi-platform support (Windows, OS X, Linux). It can be installed with pip, and the source code is available on Github.
The following code moves the mouse to the center of the screen.
import pyautogui
screenWidth, screenHeight = pyautogui.size()
pyautogui.moveTo(screenWidth / 2, screenHeight / 2)
PyAutoGUI can simulate mouse movement, click, drag, keyboard key input, hold operation, and mouse + keyboard hotkey Press and hold at the same time and other operations, it can be said that the hand can move.
pyautogui basic operation example
import pyautogui
Get the current screen resolution
screenWidth, screenHeight = pyautogui.size()
Get the current mouse position
currentMouseX, currentMouseY = pyautogui.position()
The mouse movement coordinates are 100, 100 position absolute movement
pyautogui.moveTo(100, 100)
left mouse click
pyautogui.click()
Mouse Country Move Relative Move
pyautogui.moveRel(None, 10)
double click
pyautogui.doubleClick()
Move the mouse to the (500,500) position after 2 seconds using the easing/fading function
use tweening/easing function to move mouse over 2 seconds.
pyautogui.moveTo(500, 500, duration=2, tween=pyautogui.easeInOutQuad)
Pause 0.25 seconds between each input
pyautogui.typewrite(‘Hello world!’, interval=0.25)
keyboard hit esc
pyautogui.press(‘esc’)
Hold down the shift key
pyautogui.keyDown(‘shift’)
pyautogui.press([‘left’, ‘left’, ‘left’, ‘left’, ‘left’, ‘left’])
release the shift key
pyautogui.keyUp(‘shift’)
pyautogui.hotkey(‘ctrl’, ‘c’)
PyAutoGUI keyboard table:
'enter' (or 'return' or '\n')
Enter
‘esc’
ESC
'shiftleft', 'shiftright'
Left and right SHIFT keys
‘altleft’, ‘altright’
Left and right ALT keys
‘ctrlleft’, ‘ctrlright’
Left and right CTRL keys
‘tab’ (‘\t’)
TAB键
‘backspace’, ‘delete’
BACKSPACE 、DELETE键
‘pageup’, ‘pagedown’
PAGE UP 和 PAGE DOWN键
‘home’, ‘end’
HOME and END keys
‘up’, ‘down’, ‘left’, ‘right’
arrow keys
'f1', 'f2', 'f3'….
F1…….F12 key
‘volumemute’, ‘volumedown’, ‘volumeup’
Some keyboards do not
‘pause’
PAUSE key
'capslock', 'numlock', 'scrolllock'
CAPS LOCK, NUM LOCK, and SCROLL LOCK keys
‘insert’
INS or INSERT key
‘printscreen’
PRTSC or PRINT SCREEN key
‘winleft’, ‘winright’
Win key
‘command’
Mac OS X command key
Documentation:
https://muxuezi.github.io/posts/doc-pyautogui.html
http://pyautogui.readthedocs.io/en/latest/introduction.html
http://blog.csdn.net/ibiao/article/details/54406803
The address of this article: http://www.chenxm.cc/post/547.htmlCopyright
statement: This article is an original article, and the copyright belongs to Pala. Welcome to share this article, and please keep the source for reprinting!