目录
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 = 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')