安利下这个库,解放你左手
阅读本文大概需要 3 分钟。
安装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') # 组合键
显示消息弹窗
>>> 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')
推荐阅读
1
2
3
4
评论