pywinauto入门—使用pywinauto操作PC版微信发送消息

目录

导入需要用的包

打开微信,设置好相关信息

获取微信的PID端口号,并获取主窗口

搜索联系人

发送消息


导入需要用的包

import psutil
import pyautogui
from pywinauto.application import Application

打开微信,设置好相关信息

# 打开微信的快捷键
pyautogui.hotkey('ctrl', 'alt', 'w')
# 需要发送者消息的人
searchUserName = '文件传输助手'
# 消息内容
sendMsg = "That this hates are continuous actually and longer than the sky and earth."

获取微信的PID端口号,并获取主窗口

PID = 0
for proc in psutil.process_iter():
    try:
        pinfo = proc.as_dict(attrs=['pid', 'name'])
    except psutil.NoSuchProcess:
        pass
    else:
        if 'WeChat.exe' == pinfo['name']:
            PID = pinfo['pid']

app = Application(backend='uia').connect(process=PID)
main_Win = app.window(class_name='WeChatMainWndForPC')

搜索联系人

selectItem = main_Win.child_window(title=searchKey, control_type="ListItem").wrapper_object()
selectItem.draw_outline(colour='red')
selectItem.click_input()

发送消息

inputMsg = main_Win.child_window(title="输入", control_type="Edit").wrapper_object()
inputMsg.click_input()
inputMsg.type_keys(sendMsg, with_spaces=True)

# 发送
# sendbtn = main_Win["sendBtn"]
# sendbtn.draw_outline(colour='red')
# sendbtn.click_input()

# 回车发送
pyautogui.hotkey('enter')

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

慕慕慕慕公子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值