python 控制微信发消息

直接上代码.

关键步骤说明:

打开微信,我这里用的是快捷键的方式(Ctrl+Alt+W),微信里面可以只定义的。

快捷键cttl + f 找一个叫 Tom 的人,然后给他发Hello World.

注意键盘要是英文模式,如果是中文模式,比如查找Tom的时候 就会变成中文,导致联系人找不到。

import pyautogui
import time

def Open_Wechat():
    pyautogui.hotkey('ctrl', 'alt', 'w')
    time.sleep(1)


def Chat_Who(Who_Name):
    pyautogui.hotkey("ctrl","f")
    pyautogui.write(Who_Name)
    time.sleep(1)
    pyautogui.hotkey('Enter')
    time.sleep(1)


def Sent_Msg(Msg):
    pyautogui.write(Msg)
    pyautogui.hotkey('Enter')

if __name__ == '__main__':
    Who_Name = "Tom"
    Msg = "Hello World"
    Open_Wechat()
    Chat_Who(Who_Name)
    Sent_Msg(Msg)

 

posted @ 2023-05-19 09:17  ken-yu  阅读(401)  评论(0编辑  收藏  举报