Thank you, Rohwedder, for your endeavor! I tried here and stuck at the first loop where I always have ClassNN = ""
Code: Select all
Loop
{
ControlGetFocus, ClassNN
Sleep, 100
}
Until, ClassNN = _WwG1
Yes, it does help..after reading it and combine with my intensive tests, here are my observations:
- PID is not 100% reliable, the only way to beat this problem is to place PID of WinActivate as close to Run command as possible. The following two examples demonstrate how PID is not countable.
Example1. Unliable PID if WinActivate is far away from the Run command
Code: Select all
run "iexplore" "d:\sample1.gif",,,pid1
loop 10
{sleep 100
WinActivate, ahk_pid %pid1%
if not errorlevel
break
}
sleep 100
run "iexplore" "d:\sample2.gif",,,pid2
loop 10
{sleep 100
WinActivate, ahk_pid %pid2%
if not errorlevel
break
}
sleep 100
WinActivate, ahk_pid %pid1%
sleep 100
send #{Left}
sleep 100
WinActivate, ahk_pid %pid2%
sleep 100
send #{Right}
sleep 100
msgbox "Hello--" %pid1% " , " %pid2%
ExitApp
Example2. Working example...PID is guaranteed to be useful only if WinActivate is as close to the Run command as possible
Code: Select all
run "iexplore" "d:\sample1.gif",,,pid1
loop 10
{sleep 100
WinActivate, ahk_pid %pid1%
if not errorlevel
break
}
sleep 100
WinActivate, ahk_pid %pid1%
sleep 100
send #{Left}
sleep 100
run "iexplore" "d:\sample2.gif",,,pid2
loop 10
{sleep 100
WinActivate, ahk_pid %pid2%
if not errorlevel
break
}
sleep 100
WinActivate, ahk_pid %pid2%
sleep 100
send #{Right}
sleep 100
msgbox "Hello--" %pid1% " , " %pid2%
ExitApp
- The usefulness of WinWait is ambiguous, in the both working codes, example 2 and example 3, no WinWait is used. Also, Sleep time has been reduced to the minimum and without hard coding.
Example3. Working example...PID of WinActivate is as close to the Run command as possible; no WinWait, less Sleep amount and no hard coding.
Code: Select all
run "WINWORD.EXE" /t,,,pid1
loop 10
{sleep 100
WinActivate, ahk_pid %pid1%
if not errorlevel
break
}
sleep 100
WinActivate, ahk_pid %pid1%
sleep 100
SendInput This is the first instance of Word 2007, to be placed to the left side
sleep 200
send #{Left}
sleep 100
run "WINWORD.EXE" /t,,,pid2
loop 10
{sleep 100
WinActivate, ahk_pid %pid2%
if not errorlevel
break
}
sleep 100
WinActivate, ahk_pid %pid2%
sleep 100
SendInput This is the 2nd instance of Word 2007, to be placed to the right side
sleep 200
send #{Right}
sleep 100
msgbox "Hello--" %pid1% " , " %pid2%
ExitApp