国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

python PyAUtoGUI庫實現自動化控制鼠標鍵盤

瀏覽:5日期:2022-07-11 17:48:45

PyAutoGUI 不知道你有沒有用過,它是一款用Python自動化控制鍵盤、鼠標的庫。但凡是你不想手動重復操作的工作都可以用這個庫來解決。

比如,我想半夜時候定時給發個微信,或者每天自動刷頁面等操作,它能完全模擬手動操作,而你可以安心的刷劇了。

嗯,懶惰是程序員的美德。

安裝pyautogui

pip install pyautogui

鍵盤鼠標控制

>>> import pyautogui>>> screenWidth, screenHeight = pyautogui.size() # 返回屏幕分辨率>>> currentMouseX, currentMouseY = pyautogui.position() # 返回鼠標的所在位置>>> pyautogui.moveTo(100, 150) #移動鼠標到指定位置>>> pyautogui.click() # 單擊>>> pyautogui.click(200, 220) # 單擊指定位置>>> pyautogui.move(None, 10) # 移動鼠標10個像素>>> pyautogui.doubleClick() # 雙擊鼠標>>> pyautogui.write(’Hello world!’, interval=0.25) # 輸入字符串,每個字符停留時間0.25秒>>> pyautogui.press(’esc’) # 退出鍵>>> pyautogui.keyDown(’shift’) # Shitf鍵盤>>> pyautogui.hotkey(’ctrl’, ’c’) # 組合鍵

用pyautogui自動畫圖

python PyAUtoGUI庫實現自動化控制鼠標鍵盤

顯示消息盒子

除了可以控制鼠標鍵盤外,還可以調用系統彈窗

>>> 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’

python PyAUtoGUI庫實現自動化控制鼠標鍵盤

通過窗口消息盒子可以實現一些簡單的人機交互,比如某些地方需要人工輸入內容時,這樣可以接受用戶的指令。

截屏

截圖是使用的Pillow模塊實現的,截圖的用處在于通過圖片識別技術識別圖片內容,然后通過內容精準定位到某個元素的位置,實現精準點擊。

>>> import pyautogui>>> im1 = pyautogui.screenshot()>>> im1.save(’my_screenshot.png’)>>> im2 = pyautogui.screenshot(’my_screenshot2.png’)

以上就是python PyAUtoGUI庫實現自動化控制鼠標鍵盤的詳細內容,更多關于python PyAUtoGUI庫的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 凤翔县| 吉林省| 皋兰县| 河曲县| 元阳县| 巴彦县| 宁南县| 福安市| 扶绥县| 芜湖县| 嵊州市| 武川县| 崇州市| 合川市| 拜泉县| 维西| 水富县| 通化市| 土默特右旗| 德钦县| 铁岭市| 甘孜县| 宿松县| 开平市| 新泰市| 石楼县| 大邑县| 砀山县| 都安| 巴青县| 沾化县| 资中县| 蒙山县| 临清市| 越西县| 海阳市| 清镇市| 黄大仙区| 永清县| 右玉县| 浑源县|