Fix: Alt-Taste in finally-Block freigeben

- 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.
This commit is contained in:
Andre
2026-04-04 12:33:14 +02:00
parent 0d9fb7e54c
commit c3abdf9d5a
+2 -2
View File
@@ -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)