欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 幼教 > ⭐ UI自动化工具轻松实现微信消息提醒 ⚡

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

2024/10/24 7:25:56 来源:https://blog.csdn.net/qq_39663113/article/details/140086726  浏览:    关键词:⭐ UI自动化工具轻松实现微信消息提醒 ⚡

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

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

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

pip install uiautomation

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

import timeimport uiautomation as uianow_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 = Nonechildrens = 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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com