Py之PyAutoGUI:python库之PyAutoGUI的简介、安装、使用方法

Py之PyAutoGUI:python库之PyAutoGUI的简介、安装、使用方法html

 

目录python

PyAutoGUI的简介git

PyAutoGUI的安装github

PyAutoGUI的使用方法ide


 

 

 

PyAutoGUI的简介

    PyAutoGUI是一个纯Python的GUI自动化工具,其目的是能够用程序自动控制鼠标和键盘操做,利用它能够实现自动化任务。让全部GUI都自动化¶ 本教程译自大神Al Sweigart的PyAutoGUI项目,Python自动化工具,更适合处理GUI任务,网页任务推荐。PyAutoGUI能够模拟鼠标的移动、点击、拖拽,键盘按键输入、按住操做,以及鼠标+键盘的热键同时按住等操做,能够说手能动的均可以。函数

     The purpose of PyAutoGUI is to provide a cross-platform Python module for GUI automation for human beings. The API is designed to be as simple as possible with sensible defaults.工具

 

参考文献
Welcome to PyAutoGUI’s documentation
Doc PyAutoGUIpost

 

PyAutoGUI的安装

pip install pyautoguiui

哈哈,大功告成!url

 

PyAutoGUI的使用方法

#关于库下函数使用方法概况<br>import pyautogui
 
#关于屏幕分辨率、鼠标坐标等
position=pyautogui.position() 
resolution=pyautogui.size()  
if_position=pyautogui.onScreen(1900, 2000) 
print(position,resolution,if_position)
 
#1.一、关于鼠标光标定位
pyautogui.moveTo(screenWidth / 2, screenHeight / 2) 
pyautogui.moveTo(100,100)                           
pyautogui.moveTo(x=10, y=10, duration=3)   
#缓动/渐变、Tween/Easing函数:这些效果函数是模仿Al Sweigart的PyTweening模块,能够直接使用,不须要额外安装。
pyautogui.moveTo(100, 100, 2, pyautogui.easeInQuad)    
pyautogui.moveTo(100, 100, 2, pyautogui.easeOutQuad)  
pyautogui.moveTo(100, 100, 2, pyautogui.easeInOutQuad)
pyautogui.moveTo(100, 100, 2, pyautogui.easeInBounce)  
pyautogui.moveTo(100, 100, 2, pyautogui.easeInElastic)
 
pyautogui.moveRel(None, 10) 
pyautogui.moveRel(xOffset=1000, yOffset=1000, duration=6)
 
#1.二、关于鼠标按下松开
pyautogui.mouseDown(button='right'); pyautogui.mouseUp(button='right')      
pyautogui.mouseDown(button='right')             
pyautogui.mouseUp(button='right', x=100, y=200) 
 
#1.三、关于鼠标点击
#为了操做方便,PyAutoGUI提供了doubleClick()、tripleClick()、rightClick()来实现双击、三击、右击操做
#pyautogui.click(x=moveToX, y=moveToY, clicks=num_of_clicks, interval=secs_between_clicks, button='left') 
pyautogui.click(x=100, y=200, duration=2)                
pyautogui.click(button='right', clicks=2, interval=0.25) 
pyautogui.dragTo(300, 400, 2, button='left')             
 
#1.四、关于鼠标滚动
# pyautogui.scroll(clicks=amount_to_scroll, x=moveToX, y=moveToY) 
pyautogui.scroll(10)               
pyautogui.scroll(10, x=100, y=100) 
 
#2.一、关于键盘按下松开
key_name=pyautogui.KEYBOARD_KEYS[:10] 
pyautogui.keyDown(key_name)           
pyautogui.keyUp(key_name)
 
#2.2typewrite()普通键:键盘上能够按的键均可以调用,typewrite()函数只能用于单个字符键,不能按SHITF和F1这些功能键。
pyautogui.typewrite('Hello world!\n', interval=0.1) 
pyautogui.typewrite(['a', 'b', 'c', 'left', 'backspace', 'enter', 'f1'], interval=secs_between_keys)
 
#2.3press()功能键:press()函数实际上是keyDown()和keyUp()函数的包装,模拟的按下而后松开两个动做。
pyautogui.press('esc')
pyautogui.press('enter')
pyautogui.press('f1')
pyautogui.press('left')
pyautogui.keyUp('shift')
 
#2.4热键组合;('ctrl', 'a')全选、('ctrl', 'c')复制、('ctrl', 'v')粘贴
pyautogui.hotkey('ctrl', 'a')
 
 
#三、关于消息弹窗函数:
pyautogui.alert('这个消息弹窗是文字+OK按钮')
pyautogui.confirm('这个消息弹窗是文字+OK+Cancel按钮')
pyautogui.prompt('这个消息弹窗是让用户输入消息的,单击OK')
 
#四、关于截屏的函数:屏幕位置使用X和Y轴的笛卡尔坐标系。原点(0,0)在左上角,分别向右、向下增大。  若是屏幕像素是 1920×10801920×1080 ,那么右下角的坐标是(1919, 1079)。
pyautogui.screenshot('C:/Users/99386/Desktop/screenshot.png') 
position_four=pyautogui.locateOnScreen('C:/Users/99386/Desktop/screenshot.png')
for i in pyautogui.locateAllOnScreen('C:/Users/99386/Desktop/screenshot.png'):
    print(i)
list1=list(pyautogui.locateAllOnScreen('C:/Users/99386/Desktop/screenshot.png'))
position_center=pyautogui.locateCenterOnScreen('C:/Users/99386/Desktop/screenshot.png') 
 
print(position_four,list1,position_center)

相关文章
Py之PyAutoGUI:python的PyAutoGUI库(让全部GUI都自动化)使用方法总结

相关文章
相关标签/搜索