From 278dcf41f8d1cb2db43910b6dfafad32dec19e69 Mon Sep 17 00:00:00 2001 From: jlu005807 <1289406660@qq.com> Date: Thu, 28 May 2026 11:57:50 +0800 Subject: [PATCH] fix(tui-v3): detect Shift+Enter on Windows via GetAsyncKeyState MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Windows terminals don't send unique escape sequences for Shift+Enter (both Enter and Shift+Enter arrive as \r), so prompt_toolkit can't distinguish them from the key name alone. Detect the physical Shift key via Win32 GetAsyncKeyState(0x10) — hardware-level, no terminal dependency. --- frontends/tui_v3.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frontends/tui_v3.py b/frontends/tui_v3.py index d63e2abe..64be2ad8 100644 --- a/frontends/tui_v3.py +++ b/frontends/tui_v3.py @@ -807,7 +807,12 @@ def has(*needles: str) -> bool: return any(n in a for a in aliases for n in needles) # Enter submits; Ctrl+J / Shift+Enter insert newline when PTK can distinguish. + # Windows terminals send \r for both Enter/Shift+Enter — detect Shift physically. if has('controlm', 'c-m') or key_s in ('\r', '\n'): + if _IS_WINDOWS: + import ctypes + if ctypes.windll.user32.GetAsyncKeyState(0x10) & 0x8000: + return b'\n' return b'\r' if has('controlj', 'c-j', 's-enter', 'shift-enter'): return b'\n'