


In practice, I strongly suspect it won’t help, but it was fun to write! In theory, this should give you a clue as to what’s going on… When your window loses focus, you look in the console window and see what got it. When you run this, you get a console window that opens, which you can leave running in the background. I suspect that’s what I’ll see when the issue next happens. If there isn’t a current foreground window (say if you click on the desktop), it prints “(none)”. It checks the current foreground window every second, and it has changed since the last time it reported, it dumps a line into the console window. NET Framework (not Core, although it would probably look the same if you used Core).

This is just a console application project, using. Private static void GetActiveWindow(object _, ElapsedEventArgs _) (none)") Static extern int GetWindowText(int hWnd, StringBuilder text, int count) Armed with some help from a now-extinct blog post (archive can be found here), I came up with the following, rather simple, but effective program… using System The Windows API includes a function to get the foreground window, as well as one to get the text of the current window. Putting aside the temptation to think that this is some clever piece of AI that Microsoft included in Windows to annoy you (not beyond the realms of fantasy, given how many other annoying features are in Windows already, and how reluctant Microsoft seem to be to even acknowledge that people might find them annoying), it does seem like a bug (gasp, you don’t mean…).īeing an incurable tinkerer, I decided to see if I could find out what was going on. Sometimes it can happen several times in a short space of time, then when you are waiting for it, it doesn’t happen. This issue is very hard to diagnose, partly because it only happens when you are least expecting it. The main problem is finding out what gets the focus. I can be typing an email, scrolling down through the errors in the event viewer to see what vital parts of Windows crashed today and so on, and suddenly I find that my words are not entered into the email, the events aren’t scrolling, etc.Ī quick bit of searching revealed that a lot of people have had the same problem, and very few have managed to solve it. I recently switched to Windows 10, and have found that one really annoying habit it has is that it will randomly switch focus without warning.
