原理:pyautogui + opencv进行图片识别,然后进行操作.所以记得装 pip install opencv-python
import pyautogui
import pyperclip
pyautogui.PAUSE = 1#每次延迟1秒
pyautogui.FAILSAFE=True
wechat_id="漆一" #微信账号、群号、备注,只要能搜到,但是只取结果第一个,回车默认选第一个
pyautogui.hotkey('win', 'm')
#获取微信图标位置,并点击
location1=pyautogui.locateOnScreen('./1.png', confidence=0.7)
print(location1)
pyautogui.doubleClick(location1)
location2=pyautogui.locateOnScreen('./2.png', confidence=0.7)
print(location2)
pyautogui.doubleClick(location2)
pyperclip.copy(wechat_id) # 复制到剪切板
pyautogui.hotkey('ctrl', 'v') # 粘贴到输入框,回车
pyautogui.press('enter')
i = "我是机器人"
pyperclip.copy(i) # 复制到剪切板
pyautogui.hotkey('ctrl', 'v') # 粘贴到输入框,回车
pyautogui.press('enter')
标签:pyautogui,微信,location2,pyperclip,location1,hotkey,发消息
From: https://www.cnblogs.com/qcy-blog/p/18138814