On pyautogui module

pyautogui module

PyAutoGUI-- are all automated GUI

Installation Code:

pip install pyautogui

purpose

PyAutoGUI is a pure Python's GUI automation tool, which aims can be programmed to automatically control the mouse and keyboard, multi-platform support (Windows, OS X, Linux). Pip can be installed, Github the active code.

The following code allows mouse over the center of the screen.

import pyautogui
screenWidth, screenHeight = pyautogui.size()
pyautogui.moveTo(screenWidth / 2, screenHeight / 2)

PyAutoGUI can simulate the movement of the mouse, click, drag, keyboard input, hold down operations, and mouse + keyboard hotkeys while holding down other operations, we can say the hand can be dynamic.

pyautogui basic operation of the sample

import pyautogui

# 获取当前屏幕分辨率

screenWidth, screenHeight = pyautogui.size()

# 获取当前鼠标位置

currentMouseX, currentMouseY = pyautogui.position()

# 鼠标移动坐标为100,100位置  绝对移动

pyautogui.moveTo(100, 100)

# 鼠标左击

pyautogui.click()

# 鼠标乡下移动  相对移动

pyautogui.moveRel(None, 10)

# 鼠标双击

pyautogui.doubleClick()

# 用缓动/渐变函数让鼠标2秒后移动到(500,500)位置

# use tweening/easing function to move mouse over 2 seconds.

pyautogui.moveTo(500, 500, duration=2, tween=pyautogui.easeInOutQuad)

# 在每次输入之间暂停0.25秒

pyautogui.typewrite('Hello world!', interval=0.25)

# 键盘点击esc

pyautogui.press('esc')

# 按住shift键

pyautogui.keyDown('shift')
pyautogui.press(['left', 'left', 'left', 'left', 'left', 'left'])

# 放开shift键

pyautogui.keyUp('shift')
pyautogui.hotkey('ctrl', 'c')

PyAutoGUI keyboard table:

'Enter' (or 'return' or '\ n') Enter
‘esc’ ESC
Shiftleft ',' shiftright Left and right SHIFT key
‘altleft’, ‘altright’ About the ALT key
‘ctrlleft’, ‘ctrlright’ Around the CTRL key
‘tab’ (‘\t’) TAB key
‘backspace’, ‘delete’ BACKSPACE 、DELETE键
‘pageup’, ‘pagedown’ PAGE UP and PAGE DOWN keys
‘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 key
‘insert’ INSERT or INS key
‘printscreen’ PRTSC or PRINT SCREEN key
‘winleft’, ‘winright’ Win key
‘command’ Mac OS X command key

Guess you like

Origin www.cnblogs.com/MrYang161/p/11519282.html