AutoIT: WinActivate可以把要操作的窗口提前。

If WinExists("[CLASS:Notepad2]") Then
    Local $hWnd = WinWait("[CLASS:Notepad]", "",10)
     ; Convert the handle to a string.
    Local $sHWnd = String($hWnd)
    WinActivate("[CLASS:Notepad]")
    ;WinWaitActive("[class:Notepad]")
    Send("Hello")
EndIf
原文地址:https://www.cnblogs.com/autotest/p/3262231.html