Py之PyAutoGUI:python库之PyAutoGUI的简介、安装、使用方法
Py之PyAutoGUI:python庫之PyAutoGUI的簡介、安裝、使用方法
?
目錄
PyAutoGUI的簡介
PyAutoGUI的安裝
PyAutoGUI的使用方法
?
?
?
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 PyAutoGUI
?
PyAutoGUI的安裝
pip install pyautogui
哈哈,大功告成!
?
PyAutoGUI的使用方法
#關于庫下函數使用方法概況<br>import pyautogui#關于屏幕分辨率、鼠標坐標等 position=pyautogui.position() resolution=pyautogui.size() if_position=pyautogui.onScreen(1900, 2000) print(position,resolution,if_position)#1.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.2、關于鼠標按下松開 pyautogui.mouseDown(button='right'); pyautogui.mouseUp(button='right') pyautogui.mouseDown(button='right') pyautogui.mouseUp(button='right', x=100, y=200) #1.3、關于鼠標點擊 #為了操作方便,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.4、關于鼠標滾動 # pyautogui.scroll(clicks=amount_to_scroll, x=moveToX, y=moveToY) pyautogui.scroll(10) pyautogui.scroll(10, x=100, y=100) #2.1、關于鍵盤按下松開 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')#3、關于消息彈窗函數: pyautogui.alert('這個消息彈窗是文字+OK按鈕') pyautogui.confirm('這個消息彈窗是文字+OK+Cancel按鈕') pyautogui.prompt('這個消息彈窗是讓用戶輸入消息的,單擊OK')#4、關于截屏的函數:屏幕位置使用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都自動化)使用方法總結
?
總結
以上是生活随笔為你收集整理的Py之PyAutoGUI:python库之PyAutoGUI的简介、安装、使用方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: English:daydayup
- 下一篇: Py:利用pyautogui实现自动将p