Skip to content

LAVARONG/wechat-automation-api

wechat-automation

Verified

微信发信能力:通过 Windows 桌面微信发送文本、图片URL或本地文件。适合各类 Agent 在本机直接发送一次性消息。触发词:给[某人]发微信、通知[某人]、把这个用微信发给[某人]、用微信发个图片、把本地文件发给[某人]

FileKindSize
SKILL.mdskill md9.9 KB
examples/README.mdmarkdown819 B
examples/monitor_wechat_messages.pyscript11.9 KB
examples/wx.pyscript2.1 KB
scripts/app.pyscript8.4 KB
scripts/message_queue.pyscript10.6 KB
scripts/monitor.pyscript4.4 KB
scripts/skill_cli.pyscript6.2 KB
scripts/test_wpush.pyscript2.5 KB
scripts/wechat_controller.pyscript57.6 KB

examples/wx.py

View on GitHub
import sys
import ctypes

# 确保线程绑定至用户交互式 default 桌面(避免自动化/任务环境下找不到窗口)
if sys.platform == "win32":
    try:
        h_desk = ctypes.windll.user32.OpenDesktopW("default", 0, False, 0x1FF)
        if h_desk:
            ctypes.windll.user32.SetThreadDesktop(h_desk)
    except Exception:
        pass

import uiautomation as auto
import time

# 微信主窗口:微信 4.x 架构下类名为 mmui::MainWindow,窗口名称为登录用户昵称(不能限定 Name="微信")
wx = auto.WindowControl(searchDepth=1, ClassName='mmui::MainWindow')
if not wx.Exists(0, 0):
    wx = auto.WindowControl(searchDepth=1, ClassName='WeChatMainWndForPC')
if not wx.Exists(0, 0):
    wx = auto.WindowControl(searchDepth=1, Name="微信")
wx.SetActive()
time.sleep(1)

# 激活搜索框:优先通用快捷键 Ctrl+F(避免新版微信带有“小微AI”按钮或未聚焦态为 GroupControl 的控件匹配失效)
auto.SendKeys('{Ctrl}f')
time.sleep(0.3)
search_box = auto.GetFocusedControl()
if not search_box or search_box.ControlTypeName != 'EditControl':
    search_ctrl = wx.EditControl(Name='搜索', searchDepth=25)
    if not search_ctrl.Exists(0, 0):
        search_ctrl = wx.GroupControl(Name='搜索', searchDepth=25)
    if search_ctrl.Exists(0, 0):
        search_ctrl.Click()
        time.sleep(0.3)
        search_box = wx.EditControl(ClassName='mmui::XValidatorTextEdit', searchDepth=25)

if search_box and search_box.Exists(0, 0):
    search_box.SendKeys('{Ctrl}a{Back}')
    search_box.SendKeys('线报转发{Enter}')
    time.sleep(1)

# 聊天输入框:用稳定的 AutomationId + ClassName 精确定位
# 注意:新版微信打开公众号文章/视频时右侧会出现内置浏览器面板,
# 旧写法 wx.EditControl(foundIndex=1) 会被浏览器里的输入框抢走,必须改用 AutomationId
chat_edit = wx.EditControl(
    AutomationId="chat_input_field",
    ClassName="mmui::ChatInputField",
)
# 聚焦输入框:优先使用 SetFocus 避免移动用户鼠标光标
if not chat_edit.SetFocus():
    chat_edit.Click()
chat_edit.SendKeys('你好,这是自动化测试消息{Enter}')
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall