Focus when switching to desktop
See original GitHub issueTo reproduce:
- Create two virtual desktops, open notepad on each.
- On the first desktop, click the notepad window to bring it to the foreground
- Use the windows short cut “ctrl+winkey+right arrow key” to go to second desktop
- Use
Get-Desktop 0 | Switch-Desktopto go back to first virtual desktop
Focus isn’t restored to the notepad window. Let me know if you are able to reduce this, it is somewhat intermittent.
Issue Analytics
- State:
- Created 5 months ago
- Comments:16 (9 by maintainers)
Top Results From Across the Web
Switching desktops doesn't focus front application.
My Mail app on desktop 1 will remain greyed out and unfocused, resulting in keyboard shortcuts triggering in Safari instead of Mail. I...
Read more >Apps don't gain focus when switching between them in ...
I have this weird issue where if I switch between two apps with a trackpad they do not gain focus and I have...
Read more >Windows HotKey to go (focus)to the Desktop without ...
For Windows 10, press alt+esc. It should unfocus all windows and focus on desktop.
Read more >No application focused after switching desktop
As the title says, after switching desktops, no application is focused. This is extremely annoying, because additional ALT+TAB is required ...
Read more >Why does the Focus assist auto turn on when I switch back ...
when I switch to desktop view, the Focus assist turns on automatically, then I switch to any apps in normal, it turns off....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hello,
I think I have a working solution.
After reading a lot about this, especially in the issue at mzomparelli (who should no longer be supported “openly”, as he makes closed software), @FuPeiJiang in combination with @rotemgrim’s comment gave me a solution: before switching the desktop, the focus should be placed on a window that is available on each virtual desktop, so that the focus is simply retained when switching! In VD.ahk, the taskbar (window class Shell_TrayWnd) is used for this, but I think the desktop is more useful. The idea to give away the focus with a message to minimize is a great idea (I don’t know who had it initially).
With the following code blocks (in C++) it worked for me:
. here is the code for switching the virtual desktop .
I’m not entirely happy with it because it’s probably not stable in every situation. I am still testing and experimenting…
Greetings
Markus
Hello @rotemgrim,
this is the permanent solution. However, it may not work in all cases, as it requires a certain cooperation of the displayed windows. I hope, however, it will work in almost all cases.
Greetings
Markus