1 安装pyautogui & pyperclip 三方库
pip install pyautogui
pip install pyperclip
2 自动发送微信消息.py
import time
import pyautogui as pg
import pyperclip as pc
class SendMsg(object):
def __init__(self):
self.name = '一起学python吧'
self.msg = '自动发微信消息'
def send_msg(self):
# 操作间隔为1秒
pg.PAUSE = 1.5
pg.hotkey('ctrl', 'alt', 'w')
pg.hotkey('ctrl', 'f')
# 找到狗彪子
pc.copy(self.name)
pg.hotkey('ctrl', 'v')
pg.press('enter')
# 发送消息
pc.copy(self.msg)
pg.hotkey('ctrl', 'v')
pg.press('enter')
# 隐藏微信
time.sleep(1)
pg.hotkey('ctrl', 'alt', 'w')
if __name__ == '__main__':
s = SendMsg()
while True:
# time.sleep(1)
s.send_msg()