18

A quick Google search for solutions to Focus Stealing in Windows reveals two main result categories:

  • People suggesting incomplete solutions involving the ForegroundLockTimeout registry entry (or TweakUI, which I believe simply changes the aforementioned registry entry), which isn't very effective.
  • Incessant hordes of Windows users complaining about it.

It's particularly annoying in two common scenarios:

  • Something triggers a program to popup a dialog window in the background while a fullscreen app is focused, causing the fullscreen app to minimize.

  • A window steals focus while you are typing, stealing all of your keystrokes. If you happen to press Space, Enter, or trigger a keyboard shortcut (like Y for Yes), it can cause completely undesirable outcomes.

What creative solutions can be applied to fix this problem for either or both of these scenarios?

Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
lunixbochs
  • 21,757
  • 2
  • 39
  • 47
  • 4
    The programming solution would be to write apps that don't steal focus, which doesn't seem to be what's being asked here. I think this is a job for Super User. – David Thornley May 12 '10 at 13:47
  • 1
    Super User failed to deliver on this exact issue. http://superuser.com/questions/18383/preventing-applications-stealing-focus - their only solution was the aforementioned broken ForegroundLockTimeout/TweakUI answer – lunixbochs May 12 '10 at 13:54
  • I'm going to attempt a solution for the keystroke half of the problem. I wouldn't know where to begin to universally fix fullscreen apps unfocusing. – lunixbochs May 12 '10 at 14:47

1 Answers1

2

I have one suggestion for how it can be solved, but I cannot implement it completely since I lack the knowledge.

The focus change between windows have to be instigated by the offending program calling a Windows API function located most probably in shell32 or user32. Some progams, like Adobe Photoshop makes the call multiple times (at least twice) to force itself up on the user when it's starting. The idea is to hook into this API function (if possible) and check where the call originates from. If it's not from explorer.exe (i.e. Alt+Tabbing or clicking an icon on the taskbar), then call should be blocked by said hook.

Cecil Dishwasher
  • 364
  • 2
  • 15
  • I found an API windows uses to notify programs when other programs gain focus (like for shells to display the active window). I believe it can be used to completely prevent the focus event from happening. – lunixbochs Oct 12 '11 at 17:20