python PyAutoGUI 模擬鼠標(biāo)鍵盤(pán)操作和截屏功能
簡(jiǎn)介
一款跨平臺(tái)/無(wú)依賴(lài)的自動(dòng)化測(cè)試工具,目測(cè)只能控制鼠標(biāo)/鍵盤(pán)/獲取屏幕尺寸/彈出消息框/截屏。
安裝
pip install pyautogui
鼠標(biāo)鍵盤(pán)控制
>>> import pyautogui
>>> screenWidth, screenHeight = pyautogui.size()
>>> currentMouseX, currentMouseY = pyautogui.position()
>>> pyautogui.moveTo(100, 150)
>>> pyautogui.click()
>>> pyautogui.moveRel(None, 10) # move mouse 10 pixels down
>>> pyautogui.doubleClick()
>>> pyautogui.moveTo(500, 500, duration=2, tween=pyautogui.tweens.easeInOutQuad) # use tweening/easing function to move mouse over 2 seconds.
>>> pyautogui.typewrite('Hello world!', interval=0.25) # type with quarter-second pause in between each key
>>> pyautogui.press('esc')
>>> pyautogui.keyDown('shift')
>>> pyautogui.typewrite(['left', 'left', 'left', 'left', 'left', 'left'])
>>> pyautogui.keyUp('shift')
>>> pyautogui.hotkey('ctrl', 'c')
顯示消息彈出框
>>> import pyautogui
>>> pyautogui.alert('This is an alert box.')
'OK'
>>> pyautogui.confirm('Shall I proceed?')
'Cancel'
>>> pyautogui.confirm('Enter option.', buttons=['A', 'B', 'C'])
'B'
>>> pyautogui.prompt('What is your name?')
'Al'
>>> pyautogui.password('Enter password (text will be hidden)')
'swordfish'
截屏
>>> import pyautogui
>>> im1 = pyautogui.screenshot()
>>> im1.save('my_screenshot.png')
>>> im2 = pyautogui.screenshot('my_screenshot2.png')
定位截屏
>>> import pyautogui
>>> button7location = pyautogui.locateOnScreen('button.png') # returns (left, top, width, height) of matching region
>>> button7location
(1416, 562, 50, 41)
>>> buttonx, buttony = pyautogui.center(button7location)
>>> buttonx, buttony
(1441, 582)
>>> pyautogui.click(buttonx, buttony) # clicks the center of where the button was found
參考
http://pyautogui.readthedocs.io/en/latest/index.html
https://github.com/asweigart/pyautogui
https://github.com/asweigart/sushigoroundbot
總結(jié)
以上所述是小編給大家介紹的python PyAutoGUI 模擬鼠標(biāo)鍵盤(pán)操作和截屏功能,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!
- python編程PyAutoGUI庫(kù)使用與安裝簡(jiǎn)介
- 詳解Python中pyautogui庫(kù)的最全使用方法
- Python使用pyautogui模塊實(shí)現(xiàn)自動(dòng)化鼠標(biāo)和鍵盤(pán)操作示例
- Python鍵鼠操作自動(dòng)化庫(kù)PyAutoGUI簡(jiǎn)介(小結(jié))
- Python pyautogui模塊實(shí)現(xiàn)鼠標(biāo)鍵盤(pán)自動(dòng)化方法詳解
- 使用 python pyautogui實(shí)現(xiàn)鼠標(biāo)鍵盤(pán)控制功能
- python編寫(xiě)腳本之pyautogui的安裝和使用教程
相關(guān)文章
python實(shí)現(xiàn)本地圖片轉(zhuǎn)存并重命名的示例代碼
今天小編就為大家分享一篇python實(shí)現(xiàn)本地圖片轉(zhuǎn)存并重命名的示例代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-10-10
python:目標(biāo)檢測(cè)模型預(yù)測(cè)準(zhǔn)確度計(jì)算方式(基于IoU)
今天小編就為大家分享一篇python:目標(biāo)檢測(cè)模型預(yù)測(cè)準(zhǔn)確度計(jì)算方式(基于IoU),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-01-01
pycharm通過(guò)anaconda安裝pyqt5的教程
PyCharm是一種Python IDE,帶有一整套可以幫助用戶(hù)在使用Python語(yǔ)言開(kāi)發(fā)時(shí)提高其效率的工具,這篇文章主要介紹了pycharm通過(guò)anaconda來(lái)安裝pyqt5的教程,需要的朋友可以參考下2020-03-03
python正向最大匹配分詞和逆向最大匹配分詞的實(shí)例
今天小編就為大家分享一篇python正向最大匹配分詞和逆向最大匹配分詞的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-11-11
使用Selenium在Python中實(shí)現(xiàn)錄屏功能
Selenium 是一個(gè)強(qiáng)大的用于自動(dòng)化測(cè)試的工具,但你知道它也可以用來(lái)錄制瀏覽器操作的視頻嗎?本文將介紹如何使用 Selenium 在 Python 中實(shí)現(xiàn)錄屏功能,以便記錄和分享你的網(wǎng)頁(yè)操作過(guò)程,需要的朋友可以參考下2023-11-11
Pandas剔除混合數(shù)據(jù)中非數(shù)字的數(shù)據(jù)操作
這篇文章主要介紹了Pandas剔除混合數(shù)據(jù)中非數(shù)字的數(shù)據(jù)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-03-03
Python讀取多列數(shù)據(jù)以及用matplotlib制作圖表方法實(shí)例
這篇文章主要給大家介紹了關(guān)于Python讀取多列數(shù)據(jù)以及用matplotlib制作圖表的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09

