Reputation: 33
I'm writing a script that will fill in a form in Microsoft Edge. I know I should use WinActivate
to change focus, but I don't know how to find out what the argument should be? For example if I go to Stackoverflow I can sort of guess it would be like Stack Overflow - Microsoft Edge
but if the title is longer it gets truncated in the toolbar and I honestly don't know where I can go to see the full title of a process? I tried Task Manager.
Is there a better way? It seems a bit hacky to rely on the title of the program, especially when the title of the website determines it.
Basically I'm asking, how do you use WinActive to change focus?
Process, Exist, MicrosoftEdge.exe
EdgePID = %ErrorLevel%
if( EdgePID )
{
MsgBox, Edge is running, with PID: %EdgePID%
}
WinGetTitle, Title , ahk_pid %EdgePID%
MsgBox, Title: %Title%
IfWinExist, %Title%
WinActivate ; this doesn't work
Upvotes: 2
Views: 1211
Reputation: 25752
You can use the process name which should be always the same. I'm assuming the name for Microsoft Edge is MicrosoftEdge.exe, change it if your process is named differently.
First get the process PID, which is stored in ErrorLevel
:
Process, Exist, MicrosoftEdge.exe
EdgePID = %ErrorLevel%
if( EdgePID
{
MsgBox, Edge is running, with PID: %EdgePID%
}
Then get the window title of that process, using the special command ahk_pid
:
WinGetTitle, Title , ahk_pid %EdgePID%
MsgBox, Title: %Title%
The window can be activated using the same method:
WinActivate, ahk_pid %EdgePID%
Alternatively the process name can be used directly:
WinActivate, ahk_exe MicrosoftEdge.exe
Upvotes: 2