⭐ UI自动化工具轻松实现微信消息提醒 ⚡

🌿🌿🌿🌿🌿🌿 演示效果 🌿🌿🌿🌿🌿🌿

😅😅😅😅😅😅 Python安装掠过 😅😅😅😅😅😅

 ⭐⭐⭐⭐⭐⭐ 安装uiautomation框架 ⭐⭐⭐⭐⭐⭐

pip install uiautomation

🐳🐳 🐳 🐳 🐳 🐳   代码  🐳 🐳 🐳 🐳 🐳 🐳 

import time

import uiautomation as uia

now_time = lambda : time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

# 当模块作为主程序运行时,执行以下代码
if __name__ == '__main__':
    # 初始化微信窗口对象
    wechat = uia.WindowControl(ClassName='WeChatMainWndForPC')
    # 用于记录每个好友的聊天窗口文本模式,以便后续比较
    chat_record = {}
    # 标志变量,用于控制第一次运行的逻辑
    first_run = True
    # 无限循环,持续监控微信会话列表的变化
    while True:
        # 每隔1秒检查一次
        time.sleep(1)
        # 尝试获取会话列表,如果失败则重试
        try:
            # 获取微信会话列表控件
            session_list = wechat.ListControl(searchDepth=20,maxSearchSeconds=1, Name='会话')
            # 获取会话列表的所有子项,即各个会话窗口
            childrens = session_list.GetChildren()
        except LookupError:
            # 如果找不到会话列表,打印错误信息并重试
            print('会话列表获取失败')
            session_list = None
            childrens = None
        # 如果会话列表或其子项为空,则继续下一次循环
        if session_list is None or childrens is None:
            continue
        # 遍历每个会话,记录每个会话的特定文本模式
        if childrens is not None or len(childrens) > 0:
            for item in childrens:
                # 获取好友名称
                friend_name = item.Name
                # 获取特定的文本模式,这里的路径可能需要根据UI结构调整
                text_patten = item.GetChildren()[0].GetChildren()[1].GetChildren()[1].GetChildren()[0].Name
                # 如果该好友已存在于记录中,且文本模式已改变,则打印更新信息
                if chat_record.__contains__(friend_name):
                    if chat_record[friend_name] != text_patten:
                        if not first_run:
                            print(now_time() + " " +friend_name + ":" + text_patten)
                # 如果该好友不存在于记录中,且不是第一次运行,则打印新增信息
                else:
                    if not first_run:
                        print(now_time() + " " +friend_name + ":" + text_patten)
                # 更新或新增好友的文本模式记录
                chat_record[friend_name] = text_patten
        # 控制第一次运行的标志,使得之后的运行可以进行比较
        first_run = not first_run if first_run else first_run

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值