From c3abdf9d5a354c5e6136abd6e8fc92004bbd75ae Mon Sep 17 00:00:00 2001 From: Andre <200930841+Andre-Bzk@users.noreply.github.com> Date: Sat, 4 Apr 2026 12:33:14 +0200 Subject: [PATCH] Fix: Alt-Taste in finally-Block freigeben MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Wenn bring_to_front() zwischen Alt-DOWN und Alt-UP eine Exception wirft (z.B. ungültiges Handle, fehlende Admin-Rechte), bleibt die Alt-Taste systemweit gedrückt. - Die keybd_event(VK_MENU, ..., KEYEVENTF_KEYUP) Zeile aus dem try-Block in einen finally-Block verschieben, sodass die Alt-Taste immer losgelassen wird. --- foreground_fix.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/foreground_fix.py b/foreground_fix.py index b1178d9..d6eeba8 100644 --- a/foreground_fix.py +++ b/foreground_fix.py @@ -141,8 +141,6 @@ def bring_to_front(hwnd: int) -> bool: if attached: ctypes.windll.user32.AttachThreadInput(tgt_tid, fg_tid, False) - win32api.keybd_event(win32con.VK_MENU, 0, win32con.KEYEVENTF_KEYUP, 0) - result = is_foreground(hwnd) logging.debug("bring_to_front result: %s (foreground hwnd=%s, target hwnd=%s)", result, win32gui.GetForegroundWindow(), hwnd) @@ -150,6 +148,8 @@ def bring_to_front(hwnd: int) -> bool: except Exception as e: logging.exception("bring_to_front failed: %s", e) return False + finally: + win32api.keybd_event(win32con.VK_MENU, 0, win32con.KEYEVENTF_KEYUP, 0)