要先下载一个那个Windows SDK
然后就是C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64
inspect.exe在这里
这是基础发送文本的代码:
import time
from uiautomation import uiautomation as auto
def search_and_send_message(contact_name, message="test"):
"""
搜索指定联系人并发送消息
:param contact_name: 要搜索的联系人名称
:param message: 要发送的消息内容
"""
# 激活微信窗口
wechat_window = auto.WindowControl(searchDepth=1, Name="微信", ClassName="WeChatMainWndForPC")
if wechat_window.Exists():
wechat_window.SetActive()
# 查找搜索框并输入名字
search_box = wechat_window.EditControl(Name="搜索", searchDepth=10)
if search_box.Exists():
search_box.Click()
time.sleep(1) # 等待点击生效
search_box.SendKeys(contact_name)
auto.SendKey(auto.Keys.VK_RETURN) # 模拟回车键执行搜索
# 查找输入框
edit = wechat_window.EditControl(Name=contact_name)
if edit.Exists():
# 点击输入框并发送消息
edit.Click()
edit.SendKeys(message)
# 查找并点击发送按钮
send_button = wechat_window.ButtonControl(Name="发送(S)")
if send_button.Exists():
send_button.Click()
print(f"成功发送消息给 {contact_name}")
else:
print("未找到发送按钮")
else:
print("未找到输入框")
else:
print("未找到搜索框")
else:
print("未找到微信窗口")
if __name__ == "__main__":
# 搜索联系人并发送消息
search_and_send_message("XX", "XXXX")