I just can't get new windows opened by AHK to always launch to foreground. I would expect that "Run, explorer.exe" would open a new file browser window to the front of the screen, but often it's hidden behind other windows. Same goes if I Run, putty.exe, chrome,exe, and so on. It'll be fine most of the time, but sometimes the new windows won't come forth, and then from that point it seems to happen more often than not.
I've also tried stuff from this thread:
https://autohotkey.com/board/topic/62726-run-command-doesnt-always-bring-launched-app-to-foreground/
Has anyone solved this in a reliable way for Windows 10? How are you launching your new windows/apps?
Please new window, I just want you to come forth!
Re: Please new window, I just want you to come forth!
How about WinActivate?
Re: Please new window, I just want you to come forth!
The Run command never brings the launched program to the foreground, nor does it create or show any windows. It just launches the program (or a document or shell verb).
Using WinActivate is the best you can do, although it still isn't 100% reliable because of "focus-stealing prevention" enacted by the OS. You may need to wait for the program to launch and open its window before calling WinActivate. The general pattern is:
Using WinActivate is the best you can do, although it still isn't 100% reliable because of "focus-stealing prevention" enacted by the OS. You may need to wait for the program to launch and open its window before calling WinActivate. The general pattern is:
Code: Select all
Run notepad,,, pid ; Change notepad to the desired program/command line.
WinWait ahk_pid %pid%,, 1 ; Change 1 to a different timeout value if needed.
if !ErrorLevel
WinActivate