WeChat group messaging, Windows system client (PC client
gui
uses pyside6
WeChat
is uiautomation
Main page
About page
The shortcut key to wake up WeChat
is changed to Windows
system level to wake up the WeChat window.
def __wake_up_window ():
"""唤醒微信窗口"""
hwnd = win32gui . FindWindow ( 'WeChatMainWndForPC' , '微信' )
# 展示窗口
win32gui . SetForegroundWindow ( hwnd )
win32gui . ShowWindow ( hwnd , win32con . SW_SHOWDEFAULT )
Improved the ability to obtain the nickname of the current panel for matching when there is no 100% matching of friend nicknames
# 获取到真实的昵称(获取当前面板的备注名称), 有时候输入不全, 可以搜索到,但输入内容时候会报错
def __get_current_panel_nickname ( self ) -> str :
"""获取当前面板的好友昵称"""
for idx in range ( 1 , 10 ):
current_panel_nickname = self . wx_window . TextControl ( foundIndex = idx ). Name
if current_panel_nickname :
return current_panel_nickname
When sending a message, if the friend's nickname in the current panel is the same as the friend's nickname to be sent, there is no need to search again to jump to the friend panel.
if self . __get_current_panel_nickname () != name :
self . __goto_chat_box ( name = name )
When the tool is started, both WeChat
and the tool will be on top, and WeChat
will be minimized when the tool is closed.
keyboard
monitoring module and press the shortcut key Ctrl+Alt+Q
to hide or display the tool import keyboard
keyboard . add_hotkey ( 'Ctrl+Alt+Q' , window . restore_from_tray )
Esc
and Ctrl+Alt+Q
to minimize to the taskbar. def listen_keyboard ( self ):
# 键盘监听
shortcut = QShortcut ( QKeySequence ( "Esc" ), self )
# 当按下 Esc 键时隐藏窗口
shortcut . activated . connect ( self . restore_from_tray )
psutil
import psutil
def get_specific_process ( proc_name : str = 'WeChat.exe' ) -> bool :
"""获取指定进程是否存在"""
return any ( proc . name () == proc_name for proc in psutil . process_iter ( attrs = [ 'name' ]))
pip install -r requirements.txt
pyinstaller -F -w --icon=resources/icon/icon.ico main.py
Don't do bad things, don't do bad things, don't do bad things! ! ! (But it seems like he can’t do anything bad.
GUI
, put on the agenda-2024-03-18 ThreadPool
+ QRunnable
, the tool will not freeze GUI
code. The current MVC架构
is not reasonable enough. Run main.py directly
Code for operating WeChat
In the send_msg function, whether you are sending a single message or multiple messages, you need to pass in an iterable object (eg: list(), tuple()...
You can send text and files at the same time, but not both at the same time! Send at least one of these.
# 实例化WxOperation类
wx = WxOperation ()
# 发送文本
wx . send_msg ( '好友名称' , msgs = [ 'hello' , 'world' ])
# 发送文件
wx . send_msg ( '好友名称' , file_paths = [ 'README.md' , 'wx_operation.py' ])
# 发送文本和文件
wx . send_msg ( '好友名称' , msgs = [ 'hello' , 'world' ], file_paths = [ 'README.md' , 'wx_operation.py' ])
# 批量发送
wx . send_msg ( * [ '好友1' , '好友2' ...], msgs = [ 'hello' , 'world' ], file_paths = [ 'README.md' , 'wx_operation.py' ])
# 获取微信好友
wx . get_friend_list () # 获取全部好友
wx . get_friend_list ( tag = '你的标签' ) # 获取指定标签好友
For the rest, go and look through the code yourself. It is less than 100 lines of code excluding comments.
Help us deal with the tediousness of group messaging and free our hands ( Disclaimer , this code is only for learning, please do not use it for commercial purposes after downloading)