1
votes
Func OpenSHK()
   global $Loginx = 0, $Loginy = 0, $Playx = 0, $Playy = 0
   Run(@ProgramFilesDir & "\Stronghold Kingdoms\StrongholdKingdoms.exe")
   WinWaitActive("Stronghold Kingdoms")
      If WinExists("Stronghold Kingdoms") Then
         SendKeepActive("Stronghold Kingdoms")
      Else
         WinWait("Stronghold Kingdoms")
         SendKeepActive("Stronghold Kingdoms")
      EndIf
   Sleep(5000)
   Send("testphrase")
   Local $search = _ImageSearch('pics/LoginButton.bmp', 0, $Loginx, $Loginy, 0)
      If $search = 1 Then
         MouseMove($Loginx, $Loginy, 20)
         MouseClick("left")
      Else
         Do
            $search = _ImageSearch('pics/LoginButton.bmp', 0, $Loginx, $Loginy, 0)
            sleep(5000)
         Until $search = 1
         MouseMove($Loginx, $Loginy, 20)
         MouseClick("left")
      EndIf
   Sleep(5000)
      Local $search = _ImageSearch('pics/PlayButton.bmp', 0, $Playx, $Playy, 0)
      If $search = 1 Then
         MouseMove($Playx, $Playy, 20)
         MouseClick("left")
      Else
         Do
            $search = _ImageSearch('pics/PlayButton.bmp', 0, $Playx, $Playy, 0)
            sleep(5000)
         Until $search = 1
         MouseMove($Playx, $Playy, 20)
         MouseClick("left")
      EndIf
   WinWaitActive("Stronghold Kingdoms - World 8")
   sleep(10000)
EndFunc

The function works fine, until it reaches line 6. It does not send the test phrase, and I cannot seem to figure out why.

Thanks.

2

2 Answers

3
votes

There are many errors in your code:

  1. Run("@ProgramFilesDir\Stronghold Kingdoms\StrongholdKingdoms.exe") should be Run(@ProgramFilesDir & "\Stronghold Kingdoms\StrongholdKingdoms.exe")
  2. That's why winwaitactive probably gets never passed. Try a loop instead to see if the window exists, rather than if it's active.
  3. If the window exists you can activate it then or use SendKeepActive (I think that's what it's called.)
-1
votes

When I was working with AutoIt and having a similar problem (for the same program :) ), I think I ended up using controlsend, sometimes, and send at other times. I also ended up going into the handles, and telling autoit to make specific text boxes active.