日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python_GUI操作(鼠标、键盘)

發布時間:2025/3/15 python 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python_GUI操作(鼠标、键盘) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import pyautogui,time # 獲取當前屏幕分辨率 print('當前分辨率為:' + str(pyautogui.size())) # 移動鼠標 def moveMouse(): # moveTo 指定位置畫一個正方形5次 # moveRel 當前位置畫一個正方形5次 for i in range(5): pyautogui.moveTo(100, 100, duration=0.25) pyautogui.moveTo(200, 100, duration=0.25) pyautogui.moveTo(200, 200, duration=0.25) pyautogui.moveTo(100, 200, duration=0.25) # 點擊鼠標 def clickMouse():? # 點擊2,898這個位置 pyautogui.click(2, 898) # 其他點擊事件 # pyautogui.click(100,,150,button='left') 在這個左邊位置點擊左鍵 # pyautogui.click(100,,150,button='right') 在這個左邊位置點擊右鍵 # pyautogui.doubleclick() 雙擊操作,同理也可以用在右鍵和中鍵 # 拖動鼠標 def dragMouse():? # 在畫圖中實現一個正方形旋轉圖案 time.sleep(3) distance = 200 while distance>0: pyautogui.dragRel(distance, 0, duration=0.2) ? # 向右移動 distance = distance - 5 pyautogui.dragRel(0, distance, duration=0.2) ? # 向上移動 pyautogui.dragRel(-distance, 0, duration=0.2) ?# 向左移動 distance = distance - 5 pyautogui.dragRel(0, -distance, duration=0.2) # 向下移動 # 滾動鼠標 def scrollMouse():? time.sleep(3) pyautogui.scroll(10) # 獲取屏幕快照 def getpixel():? # 獲取當前位置的RGB像素顏色,可適用于自動化中頁面跳轉驗證 time.sleep(3) RGB = pyautogui.screenshot().getpixel((0,0)) print('位置(0,0)的RGB像素為:' + str(RGB)) # 使用 pixelMatchesColor()函數判斷返回是否一致 judgeRGB = pyautogui.pixelMatchesColor(0,0,(82,146,226)) print(judgeRGB) # 鍵盤輸入 def inputKeyboard():? # 鍵盤輸入,首先要鼠標確認位置 time.sleep(3) pyautogui.click(100, 100) pyautogui.typewrite('Hello world!') # 也可以單個字符輸入,最終結果是 axyb pyautogui.typewrite('a','b','left','x','y')

'''
鍵盤鍵字符串
‘a’,'b','c','A','B','C','1','2','3','!','@' ? ? ? ? ? ? ? ? ? ?-- 單個字符串的鍵
'enter' (or 'return' or '\n') ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??-- 回車鍵
'esc'? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? -- Esc鍵
'shiftleft','shiftright'? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? -- 左右Shift鍵
'altleft','altright'? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? -- 左右Shift鍵
'ctrlleft','ctrlright'? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ?-- 左右ctrl鍵
'tab' (or '\t')? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? -- Tab鍵
'backspace','delete'? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? -- Backspace與Delete鍵
'pageup','pagedown'? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? -- Page Up與Page Down鍵
'home','end'? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? -- Home鍵 與 End 鍵
'up','down','left','right' ??? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? -- 上下左右鍵
'f1','f2'..? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? -- F1到F12鍵
'pause'? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-- Pause鍵
'''
# 移動鼠標 # moveMouse() # 點擊鼠標 # clickMouse() # 拖動鼠標 # dragMouse() # 滾動鼠標 # scrollMouse() # 獲取屏幕快照,RGB像素 # getpixel() # 鍵盤輸入 inputKeyboard

轉載于:https://www.cnblogs.com/peng-lan/p/9645588.html

總結

以上是生活随笔為你收集整理的python_GUI操作(鼠标、键盘)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。