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)