import pyautogui
import time
import pyperclip
import random

def human_like_click(x, y):
    # 模拟人类移动轨迹
    current_x, current_y = pyautogui.position()
    steps = random.randint(3, 8)
    for i in range(steps):
        target_x = current_x + (x - current_x) * (i+1)/steps
        target_y = current_y + (y - current_y) * (i+1)/steps
        pyautogui.moveTo(target_x, target_y, duration=0.1)
        time.sleep(random.uniform(0.05, 0.2))
    pyautogui.click()

def send_message():
    try:
        # 随机延迟
        time.sleep(random.uniform(0.2, 1.0))

        # 激活窗口
        win = pyautogui.getWindowsWithTitle('微信')
        if win:

            win[0].activate()
            time.sleep(0.5)

            # 定位文件传输助手
            human_like_click(652, 219)
            time.sleep(0.5)

            # 输入随机化内容
            base_msg = "你好啊世界"
            variations = ["🌍", "✨", ""]
            message = base_msg + random.choice(variations)

            pyperclip.copy(message)
            pyautogui.hotkey('ctrl', 'v')
            time.sleep(0.2)
            pyautogui.press('enter')

            print(f"[{time.strftime('%H:%M:%S')}] 发送成功")
            return True
        return False

    except Exception as e:
        print(f"发送失败: {str(e)}")
        return False

if __name__ == "__main__":
    print("程序运行中...")
    retry_count = 0
    while True:
        success = send_message()
        if success:
            retry_count = 0
            delay = 3 + random.uniform(-0.5, 0.5)  # 随机间隔
            time.sleep(delay)
        else:
            retry_count += 1
            time.sleep(5)
            if retry_count > 3:
                print("连续失败,请检查微信窗口状态")
                break

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐