给你的微信好友自动发送消息(登录电脑微信)

在这里插入图片描述

1. ai生成1000字情书(或者其他好玩的)

在这里插入图片描述

2. 放到消息里会自动识别自动断句

在这里插入图片描述
3. 效果
在这里插入图片描述

源码

import pyautogui
import pyperclip
import time
import tkinter as tk
from tkinter import messagebox
import re
import threading

# 全局变量,用于控制消息发送的循环
is_sending = False


def get_msg():
    """获取输入框中的消息,每条消息用逗号或句号分开"""
    contents = input_text.get("1.0", tk.END).strip()
    return [msg for msg in re.split(r'[,,。;.]', contents) if msg]


def send(msg):
    # 复制需要发送的内容到粘贴板
    pyperclip.copy(msg)
    # 模拟键盘 ctrl + v 粘贴内容
    pyautogui.hotkey('ctrl', 'v')
    # 发送消息
    pyautogui.press('enter')


def send_msg_task():
    global is_sending
    is_sending = True
    friend = friend_entry.get()
    if not friend:
        messagebox.showerror("错误", "请输入好友名称")
        is_sending = False
        return
    try:
        interval = float(interval_entry.get())
    except ValueError:
        messagebox.showerror("错误", "请输入有效的时间间隔(数字)")
        is_sending = False
        return
    # Ctrl + alt + w 打开微信
    pyautogui.hotkey('ctrl', 'alt', 'w')
    # 搜索好友
    pyautogui.hotkey('ctrl', 'f')
    # 复制好友昵称到粘贴板
    pyperclip.copy(friend)
    # 模拟键盘 ctrl + v 粘贴
    pyautogui.hotkey('ctrl', 'v')
    time.sleep(1)
    # 回车进入好友消息界面
    pyautogui.press('enter')
    # 一条一条发送消息
    messages = get_msg()
    if not messages:
        messagebox.showerror("错误", "请输入要发送的消息")
        is_sending = False
        return

    if repeat_var.get() == 1:
        while is_sending:
            for msg in messages:
                if not is_sending:
                    break
                send(msg)
                # 每条消息间隔设置的时间
                time.sleep(interval)
    else:
        for msg in messages:
            if not is_sending:
                break
            send(msg)
            time.sleep(interval)
    is_sending = False


def send_msg():
    # 创建并启动新线程执行消息发送任务
    thread = threading.Thread(target=send_msg_task)
    thread.start()


def stop_sending():
    global is_sending
    is_sending = False


# 创建主窗口
root = tk.Tk()
root.title("微信消息发送器")
root.geometry("400x500")
root.configure(bg="#f0f0f0")

# 设置字体
font_style = ("Arial", 10)

# 好友输入框
friend_frame = tk.Frame(root, bg="#f0f0f0")
friend_frame.pack(pady=10)
friend_label = tk.Label(friend_frame, text="好友名称:", bg="#f0f0f0", font=font_style)
friend_label.pack(side=tk.LEFT)
friend_entry = tk.Entry(friend_frame, width=30, font=font_style)
friend_entry.pack(side=tk.LEFT, padx=10)

# 消息输入框
input_frame = tk.Frame(root, bg="#f0f0f0")
input_frame.pack(pady=10)
input_label = tk.Label(input_frame, text="要发送的消息(每条消息用逗号或句号分开):", bg="#f0f0f0", font=font_style)
input_label.pack(side=tk.TOP)
input_text = tk.Text(input_frame, width=35, height=5, font=font_style)
input_text.pack(side=tk.TOP, padx=10)

# 时间间隔输入框
interval_frame = tk.Frame(root, bg="#f0f0f0")
interval_frame.pack(pady=10)
interval_label = tk.Label(interval_frame, text="每条消息时间间隔(秒):", bg="#f0f0f0", font=font_style)
interval_label.pack(side=tk.LEFT)
interval_entry = tk.Entry(interval_frame, width=10, font=font_style)
interval_entry.pack(side=tk.LEFT, padx=10)

# 单选框选择是否重复发送
repeat_var = tk.IntVar()
repeat_frame = tk.Frame(root, bg="#f0f0f0")
repeat_frame.pack(pady=10)
tk.Radiobutton(repeat_frame, text="重复发送", variable=repeat_var, value=1, bg="#f0f0f0", font=font_style).pack(
    side=tk.LEFT)
tk.Radiobutton(repeat_frame, text="仅发送一次", variable=repeat_var, value=0, bg="#f0f0f0", font=font_style).pack(
    side=tk.LEFT)

# 发送按钮
send_button = tk.Button(root, text="发送消息", command=send_msg, font=font_style, bg="#4CAF50", fg="white", padx=20,
                        pady=5)
send_button.pack(pady=10)

# 停止按钮
stop_button = tk.Button(root, text="停止发送", command=stop_sending, font=font_style, bg="#FF5722", fg="white", padx=20,
                        pady=5)
stop_button.pack(pady=10)

# 运行主循环
root.mainloop()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值