Sign in to follow this  
Followers 0
Ryan

running multiple windows

5 posts in this topic

Hey guys,

So here's my problem.

The script runs once.

But i have it run a second time, to load another window of the same game. And the windows conflict with each other. The program maximizes all the windows and the script goes insane.

So how can i run the script multiple times without it getting confused with which window it is to input all the data into.

Thanks in advance.

$file = FileOpen("config.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
; Reads Config.txt file for variables
$fullAuto = FileReadLine($file, 1)
$CheatPatch = FileReadLine($file, 2)
$CheatEngine = FileReadLine($file, 3)
$batchPath = FileReadLine($file, 4)
$sbotpath = FileReadLine($file, 5)
$sbot = FileReadLine($file, 6)
$id = FileReadLine($file, 7)
$pass = FileReadLine($file, 8)
$character = FileReadLine($file, 9)
$characterCount = FileReadLine($file, 10)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d

;;;; Body of program would go here;;;;
$sbotHandle = 0
If $fullAuto = 1 Then
;Start SBot
    Run($sbotpath & "\" & $sbot, $sbotpath)
    WinWait("SBot", "")
    Sleep(5000)
    $windows = WinList("SBot")
    $sbotHandle = $windows[1][1]

;Start SRO_Client
;MouseClick("left", 200, 300)
    ControlClick("SBot", "", 169)
EndIf

;Wait for SRO_Client, safe for all resolutions
WinWait("SRO_Client", "")
While 1
    If Not WinActive("SRO_Client", "") Then
        WinActivate("SRO_Client", "")
    EndIf
    $client = WinGetClientSize("SRO_Client", "")
    $pixel1 = $client[1] * 0.968
    $pixel2 = $client[0] * 0.073
    $pixel3 = $client[1] * 0.993
    $koord = PixelSearch(0, $pixel1, $pixel2, $pixel3, 0xFF8080, 1)
    If Not @error Then
        If PixelGetColor($koord[0], $koord[1]) = 0xFF8080 Then
            ExitLoop
        EndIf
    EndIf
WEnd
Sleep(2000)
$client = WinGetClientSize("SRO_Client", "")

MouseMove($client[0]-10, $client[1]/2)

;Login
If $fullAuto = 1 Then
    Send("{BS}")
    Sleep(100)
    Send($id)
    Sleep(100)
    Send("{TAB}")
    Sleep(100)
    Send($pass)
    Sleep(2000)
EndIf
Sleep(100)

$checksumLoginTop = PixelChecksum(0, $client[1] * 0.08, $client[0] * 0.3, $client[1] * 0.12)
$checksumLoginWindow = PixelChecksum($client[0]/2 + 60, $client[1]/2 + 50, $client[0]/2 + 100, $client[1]/2 + 100)
$checksumImageCode = 0
$checksumImageCodeValid = 0
$checksumBlockedY = 0
If $client[1] < 700 Then
    $checksumBlockedY = 550
ElseIf $client[1] < 900 Then
    $checksumBlockedY = 660
Else
    $checksumBlockedY = $client[1] * 0.9 - 10
EndIf
$checksumBlocked = PixelChecksum(350, $checksumBlockedY, 400, $client[1] - 2)

Sleep(100)
Send("{ENTER}")


;Start Cheat Engine
If $fullAuto = 1 Then
    Run($CheatPatch & "\" & $CheatEngine, $CheatPatch)
    WinWait("Cheat Engine", "")
    If Not WinActive("Cheat Engine", "") Then
        WinActivate("Cheat Engine", "")
    EndIf
        Sleep(5000)
        $windows = WinList("Cheat Engine")
        Sleep(1000)
        ControlClick("Cheat Engine 5.5", "", 169, "", 5)
        Sleep(1000)
        MouseClick ("left",25,50)
        Sleep(500)
        MouseClick ("left",410,250)
        Send ("{DOWN 150}")
        Sleep (500)
        Send ("{UP 1}")
        Sleep(500)
        Send ("{ENTER}")
        Sleep (500)
        MouseClick ("left", 910,250)
        Sleep(500)
        MouseClick ("left", 970,270)
        Sleep(500)
        Send("{BACKSPACE 3}")
        Sleep(500)
        Send("600")
        MouseClick ("left", 970,340)
EndIf

;Image Code Loop
While 1
    If Not WinActive("SRO_Client", "") Then
        WinActivate("SRO_Client", "")
    EndIf
    Sleep(100)
    
    $state = 0
    $stateCounter = 0
    While 1
        Sleep(100)
        If $checksumLoginTop <> PixelChecksum(0, $client[1] * 0.08, $client[0] * 0.3, $client[1] * 0.12) Then
            $state = 2; logged in
            ExitLoop
        Else
            $checksumImageCodeTemp = PixelChecksum($client[0]/2 + 60, $client[1]/2 + 50, $client[0]/2 + 100, $client[1]/2 + 100)
            If $checksumImageCodeTemp = $checksumLoginWindow Then
                $state = 0
                Sleep(500)
            Else
                If $checksumImageCodeValid = 0 Then
                    $checksumImageCode = $checksumImageCodeTemp
                    $checksumImageCodeValid = 1
                    $state = 1; image code
                    ExitLoop
                ElseIf $checksumImageCode = $checksumImageCodeTemp Then
                    $state = 1; image code
                    ExitLoop
                Else
                    $state = 0
                    $stateCounter = $stateCounter + 1
                    Sleep(500)
                    If $stateCounter > 10 Then
                        $checksumImageCode = $checksumImageCodeTemp
                        $state = 1; image code
                        ExitLoop
                    EndIf
                EndIf
            EndIf
        EndIf
    WEnd
    Sleep(100)
    
    
    If $state = 1 Then
    ;Image code
    ;Clear Screenshot directory
        RunWait($batchPath & "\clear_screenshots.bat")
        Sleep(1000)
        If Not WinActive("SRO_Client", "") Then
            WinActivate("SRO_Client", "")
        EndIf
        Sleep(1500)
    ;Take Screenshot
        Send("{PRINTSCREEN}")
        Sleep(1500)
    ;Call the decoder
        RunWait($batchPath & "\decode.bat")
        Sleep(1000)
        If Not WinActive("SRO_Client", "") Then
            WinActivate("SRO_Client", "")
        EndIf
        Sleep(100)
    ;Read the code
        $handle = FileOpen($batchPath & "\code.txt", 0)
        $code = FileReadLine($handle)
        FileClose($handle)
    ;Send the code
        Send($code)
        Sleep(100)
        Send("{ENTER}")
    ;Be sure this image code window disappeared before next loop,
    ;if a new image code window appears, continue on the new one
        Sleep(3000)
    ElseIf $state = 2 Then
    ;logged in
        ExitLoop
    EndIf
WEnd
;Logged in... 
Sleep(2000)
WinKill("Cheat Engine")
;Choose Character
$characterSelected = 0
If $fullAuto = 1 Then
    Sleep(1000)
    If $characterCount = 1 Then
        If $character = 1 Then
            MouseClick("left", $client[0]/2, $client[1]/2)
            $characterSelected = 1
        EndIf
    ElseIf $characterCount = 2 Then
        If $character = 1 Then
            MouseClick("left", $client[0]/4, $client[1]/2)
            $characterSelected = 1
        ElseIf $character = 2 Then
            MouseClick("left", $client[0]*3/4, $client[1]/2)
            $characterSelected = 1
        EndIf
    ElseIf $characterCount = 3 Then
        If $character = 1 Then
            MouseClick("left", $client[0]/6, $client[1]/2)
            $characterSelected = 1
        ElseIf $character = 2 Then
            MouseClick("left", $client[0]*3/6, $client[1]/2)
            $characterSelected = 1
        ElseIf $character = 3 Then
            MouseClick("left", $client[0]*5/6, $client[1]/2)
            $characterSelected = 1
        EndIf
    EndIf
EndIf
If $fullAuto = 1 And $characterSelected <> 0 Then
;Click on "Start" after character selection
    Sleep(1500)
    If $client[1] < 700 Then
        MouseClick("left", $client[0] - 268, 700)
    ElseIf $client[1] < 900 Then
        MouseClick("left", $client[0] - 268, 720)
    Else
        MouseClick("left", $client[0] - 268, $client[1] * 0.9)
    EndIf
    Sleep(3000)
;Start Auto Training :)
    $windows = WinList()
    $sbotTitle = "SBot"
    For $i = 0 To $windows[0][0]
        If $windows[$i][1] = $sbotHandle Then
            $sbotTitle = $windows[$i][0]
            ExitLoop
        EndIf
    Next
    WinActivate($sbotTitle, "")
    Sleep(6500)
    
;Start Training
    ControlClick($sbotTitle, "", 538)
    Send("{TAB}")
    Sleep(100)
    Send("{DOWN 3}")
    Sleep(100)
    Send("{ENTER}")
    Sleep(3000)
    WinMinimizeAll()

EndIf
Run($nextscriptpath & "\" & $nextscriptname )
Exit
;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func ShowMessage()
    MsgBox(4096,"","This is a message.")
EndFunc

Share this post


Link to post
Share on other sites



When you issue your run commands it will return the PID

You can use that to get the right WinHandle to each one.

Then your script will target the specific window you want.

This will get you the WinHandle

Func _WinGetByPID($iPID)
    Local $aWList = WinList()
    For $iCC = 1 To $aWList[0][0]
        If WinGetProcess($aWList[$iCC][1]) = $iPID And _
            BitAND(WinGetState($aWList[$iCC][1]), 2) Then
            Return $aWList[$iCC][0]
        EndIf
    Next
    Return SetError(1, 0, 0)
EndFunc

I found it here:

http://www.autoitscript.com/forum/index.ph...handle+from+pid

-Kenny


My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Share this post


Link to post
Share on other sites

so im confused on how that work into my program then? :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Try This

I don't have the application to test with but if it doesn't work it should at least give you an idea of how to integrate it.

-Kenny

Global $PID;Global variable to hold PID

$file = FileOpen("config.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
; Reads Config.txt file for variables
$fullAuto = FileReadLine($file, 1)
$CheatPatch = FileReadLine($file, 2)
$CheatEngine = FileReadLine($file, 3)
$batchPath = FileReadLine($file, 4)
$sbotpath = FileReadLine($file, 5)
$sbot = FileReadLine($file, 6)
$id = FileReadLine($file, 7)
$pass = FileReadLine($file, 8)
$character = FileReadLine($file, 9)
$characterCount = FileReadLine($file, 10)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage");Shift-Alt-d

;;;; Body of program would go here;;;;
$sbotHandle = 0
If $fullAuto = 1 Then
;Start SBot
    $PID = Run($sbotpath & "\" & $sbot, $sbotpath);Read PID of new process
    WinWait("SBot", "")
    Sleep(5000)
    $sbotHandle = _WinGetByPID($PID)

;Start SRO_Client
;MouseClick("left", 200, 300)
    ControlClick("SBot", "", 169)
EndIf

;Wait for SRO_Client, safe for all resolutions
WinWait("SRO_Client", "")
While 1
    If Not WinActive("SRO_Client", "") Then
        WinActivate("SRO_Client", "")
    EndIf
    $client = WinGetClientSize("SRO_Client", "")
    $pixel1 = $client[1] * 0.968
    $pixel2 = $client[0] * 0.073
    $pixel3 = $client[1] * 0.993
    $koord = PixelSearch(0, $pixel1, $pixel2, $pixel3, 0xFF8080, 1)
    If Not @error Then
        If PixelGetColor($koord[0], $koord[1]) = 0xFF8080 Then
            ExitLoop
        EndIf
    EndIf
WEnd
Sleep(2000)
$client = WinGetClientSize("SRO_Client", "")

MouseMove($client[0]-10, $client[1]/2)

;Login
If $fullAuto = 1 Then
    Send("{BS}")
    Sleep(100)
    Send($id)
    Sleep(100)
    Send("{TAB}")
    Sleep(100)
    Send($pass)
    Sleep(2000)
EndIf
Sleep(100)

$checksumLoginTop = PixelChecksum(0, $client[1] * 0.08, $client[0] * 0.3, $client[1] * 0.12)
$checksumLoginWindow = PixelChecksum($client[0]/2 + 60, $client[1]/2 + 50, $client[0]/2 + 100, $client[1]/2 + 100)
$checksumImageCode = 0
$checksumImageCodeValid = 0
$checksumBlockedY = 0
If $client[1] < 700 Then
    $checksumBlockedY = 550
ElseIf $client[1] < 900 Then
    $checksumBlockedY = 660
Else
    $checksumBlockedY = $client[1] * 0.9 - 10
EndIf
$checksumBlocked = PixelChecksum(350, $checksumBlockedY, 400, $client[1] - 2)

Sleep(100)
Send("{ENTER}")


;Start Cheat Engine
If $fullAuto = 1 Then
    $PID = Run($CheatPatch & "\" & $CheatEngine, $CheatPatch);Read PID of new process
    WinWait("Cheat Engine", "")
    $WinHandle = _WinGetByPID($PID)
    If Not WinActive($WinHandle, "") Then
        WinActivate($WinHandle, "")
    EndIf
        Sleep(5000)
        $WinHandle = _WinGetByPID($PID)
        Sleep(1000)
        ControlClick($WinHandle, "", 169, "", 5)
        Sleep(1000)
        MouseClick ("left",25,50)
        Sleep(500)
        MouseClick ("left",410,250)
        Send ("{DOWN 150}")
        Sleep (500)
        Send ("{UP 1}")
        Sleep(500)
        Send ("{ENTER}")
        Sleep (500)
        MouseClick ("left", 910,250)
        Sleep(500)
        MouseClick ("left", 970,270)
        Sleep(500)
        Send("{BACKSPACE 3}")
        Sleep(500)
        Send("600")
        MouseClick ("left", 970,340)
EndIf

;Image Code Loop
While 1
    If Not WinActive("SRO_Client", "") Then
        WinActivate("SRO_Client", "")
    EndIf
    Sleep(100)
    
    $state = 0
    $stateCounter = 0
    While 1
        Sleep(100)
        If $checksumLoginTop <> PixelChecksum(0, $client[1] * 0.08, $client[0] * 0.3, $client[1] * 0.12) Then
            $state = 2; logged in
            ExitLoop
        Else
            $checksumImageCodeTemp = PixelChecksum($client[0]/2 + 60, $client[1]/2 + 50, $client[0]/2 + 100, $client[1]/2 + 100)
            If $checksumImageCodeTemp = $checksumLoginWindow Then
                $state = 0
                Sleep(500)
            Else
                If $checksumImageCodeValid = 0 Then
                    $checksumImageCode = $checksumImageCodeTemp
                    $checksumImageCodeValid = 1
                    $state = 1; image code
                    ExitLoop
                ElseIf $checksumImageCode = $checksumImageCodeTemp Then
                    $state = 1; image code
                    ExitLoop
                Else
                    $state = 0
                    $stateCounter = $stateCounter + 1
                    Sleep(500)
                    If $stateCounter > 10 Then
                        $checksumImageCode = $checksumImageCodeTemp
                        $state = 1; image code
                        ExitLoop
                    EndIf
                EndIf
            EndIf
        EndIf
    WEnd
    Sleep(100)
    
    
    If $state = 1 Then
  ;Image code
  ;Clear Screenshot directory
        RunWait($batchPath & "\clear_screenshots.bat")
        Sleep(1000)
        If Not WinActive("SRO_Client", "") Then
            WinActivate("SRO_Client", "")
        EndIf
        Sleep(1500)
  ;Take Screenshot
        Send("{PRINTSCREEN}")
        Sleep(1500)
  ;Call the decoder
        RunWait($batchPath & "\decode.bat")
        Sleep(1000)
        If Not WinActive("SRO_Client", "") Then
            WinActivate("SRO_Client", "")
        EndIf
        Sleep(100)
  ;Read the code
        $handle = FileOpen($batchPath & "\code.txt", 0)
        $code = FileReadLine($handle)
        FileClose($handle)
  ;Send the code
        Send($code)
        Sleep(100)
        Send("{ENTER}")
  ;Be sure this image code window disappeared before next loop,
  ;if a new image code window appears, continue on the new one
        Sleep(3000)
    ElseIf $state = 2 Then
  ;logged in
        ExitLoop
    EndIf
WEnd
;Logged in... 
Sleep(2000)
WinKill("Cheat Engine")
;Choose Character
$characterSelected = 0
If $fullAuto = 1 Then
    Sleep(1000)
    If $characterCount = 1 Then
        If $character = 1 Then
            MouseClick("left", $client[0]/2, $client[1]/2)
            $characterSelected = 1
        EndIf
    ElseIf $characterCount = 2 Then
        If $character = 1 Then
            MouseClick("left", $client[0]/4, $client[1]/2)
            $characterSelected = 1
        ElseIf $character = 2 Then
            MouseClick("left", $client[0]*3/4, $client[1]/2)
            $characterSelected = 1
        EndIf
    ElseIf $characterCount = 3 Then
        If $character = 1 Then
            MouseClick("left", $client[0]/6, $client[1]/2)
            $characterSelected = 1
        ElseIf $character = 2 Then
            MouseClick("left", $client[0]*3/6, $client[1]/2)
            $characterSelected = 1
        ElseIf $character = 3 Then
            MouseClick("left", $client[0]*5/6, $client[1]/2)
            $characterSelected = 1
        EndIf
    EndIf
EndIf
If $fullAuto = 1 And $characterSelected <> 0 Then
;Click on "Start" after character selection
    Sleep(1500)
    If $client[1] < 700 Then
        MouseClick("left", $client[0] - 268, 700)
    ElseIf $client[1] < 900 Then
        MouseClick("left", $client[0] - 268, 720)
    Else
        MouseClick("left", $client[0] - 268, $client[1] * 0.9)
    EndIf
    Sleep(3000)
;Start Auto Training :)
    $windows = WinList()
    $sbotTitle = "SBot"
    For $i = 0 To $windows[0][0]
        If $windows[$i][1] = $sbotHandle Then
            $sbotTitle = $windows[$i][0]
            ExitLoop
        EndIf
    Next
    WinActivate($sbotTitle, "")
    Sleep(6500)
    
;Start Training
    ControlClick($sbotTitle, "", 538)
    Send("{TAB}")
    Sleep(100)
    Send("{DOWN 3}")
    Sleep(100)
    Send("{ENTER}")
    Sleep(3000)
    WinMinimizeAll()

EndIf
Run($nextscriptpath & "\" & $nextscriptname )
Exit
;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func ShowMessage()
    MsgBox(4096,"","This is a message.")
EndFunc

;=================NEW FUNCTION
Func _WinGetByPID($iPID)
    Local $aWList = WinList()
    For $iCC = 1 To $aWList[0][0]
        If WinGetProcess($aWList[$iCC][1]) = $iPID And _
            BitAND(WinGetState($aWList[$iCC][1]), 2) Then
            Return $aWList[$iCC][0]
        EndIf
    Next
    Return SetError(1, 0, 0)
EndFunc
Edited by ken82m

My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Share this post


Link to post
Share on other sites

Thank you Ken82m :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0