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
该功能正常,直到它到达第6行。它不发送测试短语,我似乎无法弄清楚原因。
感谢。
答案 0 :(得分:3)
您的代码中存在许多错误:
Run("@ProgramFilesDir\Stronghold Kingdoms\StrongholdKingdoms.exe")
应该是Run(@ProgramFilesDir & "\Stronghold Kingdoms\StrongholdKingdoms.exe")
winwaitactive
可能永远不会传递的原因。尝试使用循环来查看窗口是否存在,而不是它是否处于活动状态。SendKeepActive
(我认为这就是所谓的。)答案 1 :(得分:-1)
当我使用AutoIt并遇到类似的问题时(对于相同的程序:)),我想我最终会使用controlsend,有时会在其他时间发送。 我最后也进入了句柄,告诉autoit使特定文本框处于活动状态。