From 75298253576e232db61947c836f18ca2b4e6f944 Mon Sep 17 00:00:00 2001 From: youpaishidifu Date: Sat, 25 Jul 2026 17:09:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AEQQ=E8=AF=BB=E4=B8=8D=E5=88=B0=E6=B6=88?= =?UTF-8?q?=E6=81=AF=EF=BC=9A=E6=81=A2=E5=A4=8D=E9=94=AE=E7=9B=98=E5=AF=BC?= =?UTF-8?q?=E8=88=AAEsc=E2=86=92Esc=E2=86=92Enter=E4=B8=8D=E5=88=87?= =?UTF-8?q?=E4=BC=9A=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- monitor.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/monitor.py b/monitor.py index e2939a3..805923b 100644 --- a/monitor.py +++ b/monitor.py @@ -401,11 +401,24 @@ class MessageMonitor: return [] # 注意:不再执行 {Esc}{Esc}{Down}{Enter} 键盘导航,避免每次 poll - # 切换到不同会话导致读到不同消息集。直接 Ctrl+A/C 读取当前可见对话。 - # 若需滚动到底部,用 PostMessage(不影响焦点) - hwnd_current = self._cached_hwnd.get(platform) - if hwnd_current: - win32gui.PostMessage(hwnd_current, win32con.WM_VSCROLL, win32con.SB_BOTTOM, 0) + # 切换到不同会话导致读到不同消息集。改用 Esc→Esc→Enter + # 回到会话列表后重新打开当前(同一)对话,确保消息区可读。 + variant = self._app_variant.get(platform, "") + if variant in ("tim", "qq_nt"): + VK_ESC = 0x1B + VK_RETURN = 0x0D + VK_END = 0x23 + VK_CONTROL = 0x11 + # 取消弹窗/菜单,回到会话列表 + self._send_key_press(VK_ESC, 0.08) + self._send_key_press(VK_ESC, 0.08) + # 重新打开当前选中的对话(同会话,不切换) + self._send_key_press(VK_RETURN, 0.4) + # Ctrl+End 滚动到底部 + ctypes.windll.user32.keybd_event(VK_CONTROL, 0, 0, 0) + self._send_key_press(VK_END, 0.05) + ctypes.windll.user32.keybd_event(VK_CONTROL, 0, 2, 0) + time.sleep(0.3) # 用 SendInput 替代 auto.SendKeys(避免 ord() Unicode 解析 bug) VK_A = 0x41 @@ -530,6 +543,13 @@ class MessageMonitor: """SendInput KEYBDINPUT keyup (KEYEVENTF_KEYUP=2).""" ctypes.windll.user32.keybd_event(vk, 0, 2, 0) + @staticmethod + def _send_key_press(vk: int, delay: float = 0.05): + """SendInput single key press (down + up).""" + ctypes.windll.user32.keybd_event(vk, 0, 0, 0) + time.sleep(delay) + ctypes.windll.user32.keybd_event(vk, 0, 2, 0) + @staticmethod def _send_ctrl_combo(vk: int): """Send Ctrl+: Ctrl down → key down → key up → Ctrl up."""