How can I prevent focus stealing in Windows?

◇◆丶佛笑我妖孽 提交于 2019-12-18 12:52:32

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/2819277/how-can-i-prevent-focus-stealing-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!