Hacker News new | ask | show | jobs
by dataflow 308 days ago
> It has always felt insane to me that macOS and Windows will both just let some random auto-updater steal focus and eat your keystrokes while trying to work on something.

Wait, what? Hasn't Windows prevented focus stealing for literally decades at this point?

https://devblogs.microsoft.com/oldnewthing/20090220-00/?p=19...

3 comments

It used to block focus stealing aggressively unless a program had foreground permission or was given it (AllowSetForegroundWindow), but the mechanism seems broken in current versions of Windows.
Do you have a link to more details or something? I haven't seen or heard of what you describe.
Afraid not. The documentation for AllowSetForegroundWindow() and the associated mechanism still exists, of course:

https://learn.microsoft.com/en-us/windows/win32/api/winuser/...

But the last time I tried to test code using this to properly hand off foreground permission from one process to another, I had a hard time testing it because I couldn't get it to fail. When this mechanism was first introduced in Windows 98 and 2000, it was pretty aggressive -- if you were past the input timeout and foreground permission hadn't been forwarded or already shared, the target application would fail to come to the front and its taskbar button would light up instead. I haven't seen this happen in a long time on current Windows, programs steal focus all the time.

Haven't used windows in a decade, but there is (was?) a registry setting that would disable focus stealing prevention. Some egregious tools "helpfully" changed that setting for you when you installed them, because they couldn't get focus management to work properly. Maybe it's that?
Interference from some program is a possibility, but the relevant foreground lock registry keys seem default on all my systems.
I'm pretty sure something weird is going on in your case because I recently had to fight a case of this that had seemingly gotten more aggressive in Windows 11, not less. The focus stealing prevention has always been there and is still there as far as I've observed.
An app can still steal focus with `uiAccess=true` in the app manifest's execution level (and the app is signed).
Ah, that may be the case - I’ll edit my comment. I was primarily using macOS before this so I may have misremembered the Windows behavior.