microsoft / PowerToys

Windows system utilities to maximize productivity
MIT License
111.19k stars 6.54k forks source link

Disable focus stealing #65

Open chris400 opened 5 years ago

chris400 commented 5 years ago

The old TweakUI had an option to disable focus stealing. I am a real power user: while launching several apps I am writing emails, notes, documents and so on. But when another app has been finished the startup it steals the focus. Other times this happens when an app shows a pop-up.

Pls bring back an option to disable focus stealing

Adrian-Grimm commented 5 years ago

Maybe also an additional mode: If an application steals focus and the user is typing in a different application, it should be only transparent on top but gets not the focus of the keyboard-cursor - so the user can finisch typing. If the user then manualy focuses the transparent window on top everything it turns "normal" again.

belg4mit commented 5 years ago

XMouse-like tools can help mitigate this, but not everybody likes that behavior so this could be handy.

lordlycastle commented 5 years ago

Agh. Microsoft Teams is a horrible app that does this at least few times a day to "Update". So annoying as you're writing something and it just steals it and doesn't return and have to alt-tab to return where you were. What the hell are they updating few times a day anyways.

jabbott-dm commented 5 years ago

I can't up-vote this enough !

pgaske commented 5 years ago

Windows stealing focus irritates me so much that I sometimes want Windows 2000 back - just for its default behaviour of disallowing focus stealing.

RohanSinghRajput commented 5 years ago

As jabbott-dm said, we can't upvote this enough! Perhaps one could just Google "Focus Steal" / "Focus Stealing" and realize how frustrated people are with this issue. Bigger problem is that there is no simple solution available to normal users. Only those with programming experience in c++ can develop a solution By injecting a DLL into every process running with user privileges, to "hook" (redirect) the process' system calls to SetForegroundWindow to an empty function Credit for the above suggestion to Matúš who has created a lovely utility. The idea for the same came from https://superuser.com/questions/18383/preventing-applications-from-stealing-focus and the utility is available for download at https://blade.sk/stay-focused/. Direct download link for the file at https://blade.sk/stay-focused/StayFocusedBeta1.zip. The utility is still unfinished and needs some fine tuning. Please, please, please give preference to addressing this annoying behavior, that reduces productivity, rather deploying resources for developing desirable features that could be play toy at best. Thanks.

michael-hawker commented 4 years ago

Yeah, I hit this all the time, I'd love to just have a toggle button in the PowerToys setting to change this! 🦙❤

LiamKarlMitchell commented 4 years ago

When I get a message on teams whilst I'm playing a game full screen it steals focus... Why...

Avasam commented 4 years ago

Replying to get updates on this issue. I'm trying to play Pitfall: The Lost Expedition, an old 2000 - XP SP2 era game that aggressively steals focus every frame (that every 1/60th of a second!). It's so bad that softlocking in-game (which happens every few hours) means having to reboot my entire computer.

jstuyts commented 3 years ago

Contact this person and ask them if you can integrate their solution: https://github.com/bladeSk/StayFocused

I have been loathing this Windows behavior the last couple of decades, and this solution is the first that works well.

Aaron-Junker commented 3 years ago

Contact this person and ask them if you can integrate their solution: https://github.com/bladeSk/StayFocused

I have been loathing this Windows behavior the last couple of decades, and this solution is the first that works well.

/Cc @crutkas

crutkas commented 3 years ago

Contact this person and ask them if you can integrate their solution: https://github.com/bladeSk/StayFocused

I have been loathing this Windows behavior the last couple of decades, and this solution is the first that works well.

Issue is they lack a license but we could. This isn't something we are proactively focusing on however per roadmap. If they want to partner, if someone wants to help do the work, this could be something we'd want to integrate.

enricogior commented 3 years ago

Anyone considering to contribute to PowerToys, porting StayFocused to PowerToys, should be aware that we may not accept code that uses DDL injection.

ghost commented 3 years ago

@enricogior You meant DLL injection?

albanoalfredo commented 3 years ago

Please consider this in your roadmap. I even put the programs on different desktops but they still keep stealing focus. Photoshop is probably the most annoying one, steals focus several times when booting.

crutkas commented 3 years ago

@albanoalfredo walk through the process of how it steals focus.

  1. click photoshop in task bar
  2. I do action XYZ
  3. Photoshop splash screen
  4. I do something else, PS is no longer in focus
  5. i do something else
  6. Photoshop fully started
  7. Photoshop steals focus
albanoalfredo commented 3 years ago
  1. I go to desktop 2
  2. Open photoshop
  3. Go to desktop 1
  4. Photoshop appears on desktop 1
  5. start writing this comment
  6. photoshop steals focus and appears on top
  7. I manually return to this comment
  8. Photoshop fully started on desktop 1.

I specifically open it on desktop 2 to avoid it stealing focus, but it still opens on desktop 1 and steals focus and least once. Lightroom does the same thing, as well as other programs, but these I know they do it everytime I open them.

LiamKarlMitchell commented 3 years ago

Is this a matter of intercepting the Window Message for taking focus and preventing it from reaching the target window proc?

Ideally: Disabling this Bring to Foreground functionality, but the task bar should still light up to indicate it wants attention.

patware commented 3 years ago

Agreed (+1) with @LiamKarlMitchell about "full screen steeling" when gaming, but also when giving a PowerPoint presentation or watching a movie. Windows 10 has a "Focust assist" setting for notifications.

Another frustration is when (fast) typing in code or in a document and a dialog window happens to popup seeking your confirmation at the same time you hit the [space bar] or the [enter key]. Something happens and you have no clue "what application" nor "what action" was performed. You just happen to get lucky to see that a popup did come up for a milisecond that's it.

michael-hawker commented 3 years ago

Another frustration is when (fast) typing in code or in a document and a dialog window happens to popup seeking your confirmation at the same time you hit the [space bar] or the [enter key]. Something happens and you have no clue "what application" nor "what action" was performed. You just happen to get lucky to see that a popup did come up for a milisecond that's it.

💯 this. I'll be typing mail or code or something. Something else happens and it steals focus and no idea what I just did...

This would be a multi-tasking dream.

Especially when running compilation, and then your own app starts, but you had gone to do something else while it was building. The scenarios go on and on...

michael-hawker commented 3 years ago

Was just thinking too, it's not just about focus stealing, but if the app launches on top of your existing app, then if you were clicking too then the new app would grab that vs. the app that currently has focus remaining on top/foreground of the newly launched app...

Edit: That looks like its related to issue #22

ThermoMan commented 3 years ago

I too need a fix.

It is such a pervasive and long standing problem that there was even a change.org petition to fix it. https://www.change.org/p/microsoft-stop-focus-stealing

(But it really ought to be part of the operating system)

Inari-Whitebear commented 3 years ago

The single most annoying thing about windows that MS refuses to add an option to stop

darkquake93 commented 3 years ago

Agreed (+1) with @LiamKarlMitchell about "full screen steeling" when gaming, but also when giving a PowerPoint presentation or watching a movie. Windows 10 has a "Focust assist" setting for notifications.

Another frustration is when (fast) typing in code or in a document and a dialog window happens to popup seeking your confirmation at the same time you hit the [space bar] or the [enter key]. Something happens and you have no clue "what application" nor "what action" was performed. You just happen to get lucky to see that a popup did come up for a milisecond that's it.

Yep definitely while gaming; was just on Apex and suddenly "something" stole focus and I had to quickly click back in (I would've alt-tabbed, but I use an Autohotkey script to disable that so I don't accidentally do that while gaming, along with the Windows Keys).

No idea what but I suspect it was Steam's webhelper service as that had stolen focus in the past. I have a shortcut to run Steam without the browser, but then I can't access any store features. Not too bad.

Mainly though would love an option to turn focus stealing off, or at least an easy way to identify which app it was that stole the focus!

covellitenz commented 3 years ago

This is my number 1 pet peeve with Windows. There are so many situations where this occurs. If it's not going to be fixed in Windows itself, then a switch in PowerToys would be the next best thing.

LiamKarlMitchell commented 3 years ago

@darkquake93 Actually that happened to me again the other week with Microsoft Teams. Was playing some Apex and get a message from a workmate and boom.

But yes typing and accidental triggering of dialogs just because they stole focus is a pain too especially when its something wanting to restart your computer such as after installing a program.

Regarding alt+tab, you can disable just the left alt key from doing alt tab functionality but keep the right one working just in-case. Left windows key gets unbound too. PowerToys actually has a Keyboard Manager to remap keys, have not tried it yet.

CuteWaterBeary commented 2 years ago

Is it possible to set an app to behave exactly as on-screen keyboard does? I can get an app to be always on top using PowerToys but I can't make the app stop taking active focus. The app is a column I keep on the right side of my screen which has visual buttons that send MIDI outputs which effect a game I'm playing but I don't want the game to lose focus.

crutkas commented 2 years ago

@Original-Creator this is a different ask. You have some app that sends commands to an app, chances are to do so it focus that application and sends command.

This is a background application that takes focus. While they are similar, they are different.

darkquake93 commented 2 years ago

@darkquake93 Actually that happened to me again the other week with Microsoft Teams. Was playing some Apex and get a message from a workmate and boom.

But yes typing and accidental triggering of dialogs just because they stole focus is a pain too especially when its something wanting to restart your computer such as after installing a program.

Regarding alt+tab, you can disable just the left alt key from doing alt tab functionality but keep the right one working just in-case. Left windows key gets unbound too. PowerToys actually has a Keyboard Manager to remap keys, have not tried it yet.

@LiamKarlMitchell Yeah I wouldn't run Teams on the same machine you're gaming on; good to have the work-play separation ;) Or if you have to, the Web Teams might be a better option and it won't steal focus.

As for working out what is stealing focus, I came across https://github.com/JocysCom/FocusLogger which I'll need to get more in the habit of running while playing Apex. It happened again today but hadn't for a while, I'll find the culprit eventually! :p

LiamKarlMitchell commented 2 years ago

I ended up having Teams installed on my phone and killing the one on desktop whilst gaming. But sometimes I forget too. Would be nice to have a software solution preferably one that does not involve injecting DLL into every process to hook things. Registry tweaks mentioned online don't seem to work.

Teams is not the only annoyance, things like Alarms if you set them on Windows 10, will pop up a notification in the bottom right whilst you have a full screen application running...

KateHanami commented 2 years ago

please make this into a thing the other day I was trying to install unity for personal reasons I was chatting with someone on discord while it was installing ON THE BACKGROUND and when it got to Visual Studio installer, it decided to steal focus from discord as I was typing a message wouldn't you know it? the "cancel" button was highlighted by default naturally I need to press spacebar in the message, the bloody thing just cancelled itself without asking me "are you sure?" I'm not a blind-typer, so I still need to look at my keyboard to be sure, not helpful to have anything stealing focus all willy-nilly

Inari-Whitebear commented 2 years ago

Yeah, I hate when such things happen. I don't look at my keyboard, but sometimes things still pop up just as you're hitting spacebar (which counts as selecting the button)

LiamKarlMitchell commented 2 years ago

https://www.change.org/p/microsoft-stop-focus-stealing petittion closed :( nothing done. Some decisions about possible implementations here: https://social.technet.microsoft.com/Forums/en-US/c22363e5-802c-4f43-b4e3-8a7259865648/windows-10-stop-any-application-from-stealing-focus-ever-is-it-possible?forum=win10itprogeneral

Could be done by injecting a dll into all processes one for 32bit one for x64, but worry that would set of game anti cheats. Maybe a blacklist of processes to not inject into would be a good measure.

This shows a way to log them, presumably if it can log it can also prevent them being received. https://github.com/yinkaisheng/MyLiteSpy

Similar could hook this one and prevent it running. https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setfocus

brimwats commented 2 years ago

This has gotten increasingly worse in Windows 11, especially with multiple monitors. I've changed Computer\HKEY_CURRENT_USER\Control Panel\Desktop\ForegroundLockTimeout a bunch of times to try to mitigate, but it only helps minimally.

LiamKarlMitchell commented 2 years ago

Maybe this could be used to hook it and ignore, wonder what the x64 alternative is. https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwineventhook

A better implementation might be to have a list of processes that are allowed to steal focus. Not sure how it will play with UAC or Firewall prompts for example.

Jthwaits commented 2 years ago

How can I upvote a thread more than once? Focus stealing happens to me all the time with background apps and I can't get rid of it.

pgaske commented 2 years ago

... the bloody thing just cancelled itself without asking me "are you sure?" ...

Could you imagine a catastrophic thing happening due to focus stealing? OP's "do you want to cancel setup" will be someone else's "start over-pressure relief procedure" with Cancel selected as default being obliviously space-bar cancelled because someone was writing a message elsewhere.

cwade12c commented 2 years ago

Big upvote here. Focus stealing is one of the worst plagues to exist. It would be an insanely productive performance boost to do away with it.

cloopadoop commented 1 year ago

+1ing, +1000ing

darkquake93 commented 1 year ago

I ended up having Teams installed on my phone and killing the one on desktop whilst gaming. But sometimes I forget too. Would be nice to have a software solution preferably one that does not involve injecting DLL into every process to hook things. Registry tweaks mentioned online don't seem to work.

Teams is not the only annoyance, things like Alarms if you set them on Windows 10, will pop up a notification in the bottom right whilst you have a full screen application running...

@LiamKarlMitchell Sorry for the late reply, just come back to this. Still good to have the work-play separation, I'd disable Teams from Startup Items and just use Web Teams (with notifications silenced) if you have to on your main PC, hopefully that'll do the trick. Plus check out the FocusLogger, I have this on startup too in case it happens again (hasn't again so far) https://github.com/JocysCom/FocusLogger

For the alarms, check out customisation of Focus assist (from searching in the Start Menu). Set your automatic rules to Priority only when playing a game etc, and your priority list unchecked for the "texts" & "people" sections. I don't use any Win10 alarms, only on my watch or mobile.

That's all I can think of, apart from the DLL injection approach (which as you say might trigger anti-cheat stuff, but given we both play Apex let me know if you give that a go and it works). Good luck!

Griefed commented 1 year ago

This doesn't seem to have enough upvotes yet. Have one more!

I absolutely hate it when an app steals the focus from me. More often than not do I start several apps or tasks, only to continue working on some other unrelated task. At least I would love to, if it weren't for every aforementioned app and task then fighting for my attention as every single one of them is of the impression "Oh, you started me, that means you want to USE ME RIGHT THIS INSTANT RIIIIIGHT? RIIIIIIIIIIGHT?"

Like that one, sometimes, annoying friend, who won't stop bugging you until you respond, only to then simply say "Hi." 😂

Hezkezl commented 1 year ago

It's absolutely insane that this is still a thing... especially if it defaults to having 'cancel' be the only button that can be clicked if you're in the middle of typing something and hit space bar...

Extract something huge with Winrar, it finishes. Then windows pops up ANOTHER file transfer box that you can cancel, which you wind up doing most of the time if you're typing a message (like this one right now) and not paying attention to something that's taken over an hour to do...

Just don't have it pop up and steal focus away if it's not the active app in the foreground, why is that such a hard concept to understand? :(

felipecrs commented 1 year ago

Just don't have it pop up and steal focus away if it's not the active app in the foreground, why is that such a hard concept to understand? :(

I don't think this is hard to understand, but maybe this is so deep into Windows which makes it hard to implement.

chylex commented 1 year ago

Just wasted 15 minutes of Bluetooth transfers because the stupid dialog that asks where to save the files appeared as I was pressing Escape. I understand it's hard to stop third party applications from stealing focus, but this dialog was part of Windows itself, so there's no excuse for it behaving so poorly. Wish Microsoft did something about this, it's so annoying.

lvguedes commented 10 months ago

Please fix it. I upvote and totally support this idea.

New feature spec

Add some kind of switch within PowerToys so that we can configure if other apps are enabled to steal focus or not. This is annoying when a random window is created and steal focus when I'm typing in another window, yet possibly in another monitor. Make sure this new switch works in a multiple monitors setup.

Fix a bad OS design choice

In most cases there is not why any window steal user focus because the user is the primary controller of the system. Any OS shall be developed to assist the user complete his/her objectives, not to rule, take control from the user, or interrupt the user when he/she is typing or doing some other activity. The focus should be primarily from the user because it represents the point in which user interacts with the system, obviously changing it suddenly will only disturb the user. The windows stealing focus when opening demonstrate to us a poor architecture design choice from Microsoft.

Scenario in which this new feature is brilliant

If the user chooses to run an automation while, in parallel, writes a report in another window, always that the automation start a new window, it interrupts the user from typing. Worst yet, all the typed content goes to the window automation opened, possibly breaking the automation execution too.

The new feature would solve it elegantly.

Possible implementation to investigate

As we don't have access to how windows does things in the background, maybe we could solve this issue using the Windows API. A simple algorithm to try to integrate to PowerToys:

  1. Get the window handle which has the focus when user press the activation key sequence (same of Always on Top)
  2. Create an infinite loop which calls https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setfocus on handle. With a configurable delay between each call, so we can get a bit of bare control over performance.
  3. Listener to break the loop when the switch state change to off in the PowerToys UI.
  4. Listener so that when the UI switch state is changed to on the loop starts.
  5. Place a text field (input decimal numbers) at the side of the switch in UI where we can configure the delay in seconds.

Similar to the Always on Top module, the one proposed above would make the focus stay fixed in the window where the user pressed the activation shortcut keys.

A better yet solution would be able to identify the window which user is working on automatically without the need of activation key pressing (maybe through mouse cursor position, or some other strategy). Configurable options in UI that enable us to choose the strategy would be great.

Aubrey-Russell commented 8 months ago

Its 2024 and focus stealing is still just as annoying as ever. I'll talk to you guys again in 2030 though.

Hopefully in the near future the new LLM Gods will create a workaround or fix.

SoraHjort commented 2 months ago

Honestly, this should be built into the OS and not rely on additional software, regardless if it's powertoy or otherwise. There have been times when I've been typing in login information after starting up a computer and a window, such as a powershell script running, will steal focus as the computer is still starting up. There have also been times when I've been typing into a chat, only for some software to have update in the background and bringing up their window to notify that it's been updated. There have been times when the program that steals focus is then messed with because the keys being typed activate commands.

It's beyond an annoyance, it's also a security issue, hence this should be baked into the OS. BUT, if PowerToys can implement this, then that is better than the current state of things. And it's not like it's always been an issue either, back on XP you could actually change a registry option to prevent focus stealing.

So, yeah, I hope something can be done about it.

pgaske commented 2 months ago

There have been times when I've been typing in login information after starting up a computer and a window, such as a powershell script running, will steal focus as the computer is still starting up.

This has literally caused me to have to change passwords because a sensitive password was accidentally entered into the window that stole focus.

brimwats commented 2 months ago

This has literally caused me to have to change passwords because a sensitive password was accidentally entered into the window that stole focus.

Same here

LiamKarlMitchell commented 2 months ago

Yeah leaking the password to anyone who may be watching is not cool, Or it shuts down a machine when your still doing work 😄, or crashes a full screen game just because someone likes or comments on ms teams after hours...

But basically every os has this problem of focus stealing right?

On Tue, 20 Aug 2024, 2:12 pm bri watson, @.***> wrote:

This has literally caused me to have to change passwords because a sensitive password was accidentally entered into the window that stole focus.

Same here

— Reply to this email directly, view it on GitHub https://github.com/microsoft/PowerToys/issues/65#issuecomment-2297831141, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPAP3LDXYZXSMXDL46JPKLZSKQXRAVCNFSM4HL72Y4KU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMRZG44DGMJRGQYQ . You are receiving this because you were mentioned.Message ID: @.***>