Jump to content
Sign in to follow this  
fielpo

merge 2 script

Recommended Posts

fielpo

hi, i have one script that open a program and click on some button and works fine (it`s forthe program bring) now for how i use it, the windows of bring get closed.

i need that the program check if the windows is still open if not will restart the script. i tried to make a separate script but i get an error so if it can be just one script that works in loop.

here the code i get for a separate scriptfor run in loop

ShellExecute("cmd.exe") ; <<<<< Test using CMD.
Sleep(500) ; <<<<< Wait for CMD to Start.
While 1
    If Not WinExists("[CLASS:ConsoleWindowClass]") Then $PID = Run("cmd.exe") ; <<<<< Use AU3Info Tool in SciTE > Tools to get the CLASS name of the window.
    Sleep(100) ; Sleep  Wait.
WEnd
Exit

that i will like integrate on this one:

#include <Array.au3>
#include <functions.au3>

;Read settings from settings file
$BringExe = IniRead("settings.ini", "Settings", "BringExe","")
$BringPath = IniRead("settings.ini", "Settings", "BringPath","")
$BringHost = IniRead("settings.ini", "Settings", "BringHost","")
$TitleText = IniRead("settings.ini", "Settings", "TitleText","")

Dim $TableCoords[6][2]
Dim $TableCoordsOpen[6]

;Read the desired table coordinates from the settings file
$tmp = StringSplit(IniRead("settings.ini","Settings","Table1Pos",""),",",1)
$TableCoords[0][0] = $tmp[1]
$TableCoords[0][1] = $tmp[2]
$TableCoordsOpen[0] = 1;
$tmp = StringSplit(IniRead("settings.ini","Settings","Table2Pos",""),",",1)
$TableCoords[1][0] = $tmp[1]
$TableCoords[1][1] = $tmp[2]
$TableCoordsOpen[1] = 1;
$tmp = StringSplit(IniRead("settings.ini","Settings","Table3Pos",""),",",1)
$TableCoords[2][0] = $tmp[1]
$TableCoords[2][1] = $tmp[2]
$TableCoordsOpen[2] = 1;
$tmp = StringSplit(IniRead("settings.ini","Settings","Table4Pos",""),",",1)
$TableCoords[3][0] = $tmp[1]
$TableCoords[3][1] = $tmp[2]
$TableCoordsOpen[3] = 1;
$tmp = StringSplit(IniRead("settings.ini","Settings","Table5Pos",""),",",1)
$TableCoords[4][0] = $tmp[1]
$TableCoords[4][1] = $tmp[2]
$TableCoordsOpen[4] = 1;
$tmp = StringSplit(IniRead("settings.ini","Settings","Table6Pos",""),",",1)
$TableCoords[5][0] = $tmp[1]
$TableCoords[5][1] = $tmp[2]
$TableCoordsOpen[5] = 1;

_StartBring($BringExe, $BringPath, $BringHost)


;Loop through the Bring Listbox, save all open windows in the Bring list and add them temporary to the $Tables array
;Had to use this ugly workaround because I was not able to access the listbox directy through API calls.
;There is a thread on the forums that discuss this issue. Apparently it would require the AutoIt3Lib.
$loop = 1
$i = 1
Dim $Tables[1]
While $loop == 1
    
    $var = ControlCommand("Select Remote Window", "", 1005, "GetCurrentSelection", "")
    
    _ArrayAdd($Tables, $var)
    
    If $Tables[$i] == $Tables[$i-1] Then
            _ArrayDelete($Tables, $i) ;Delete the last Array entry as its a duplicate now
            _ArrayDelete($Tables, 0) ;Delete the first Array entry as its empty
            $loop = 0
    EndIf
    
    $i = $i+1
    Send("{DOWN}")
WEnd

$c = 0
while $c < Ubound($Tables)
    if StringInStr($Tables[$c],"Program Manager") Then
        _ArrayDelete($Tables,$c)
    EndIf
    $c = $c + 1
WEnd

$icounter = 0
$windows = WinList()
   For $Key = 1 To $windows[0][0]-1
    If stringinstr($windows[$Key][0],$TitleText)<>0 Then
        ;we found a table running
        ;find the table in the array and delete it
        ;check dimensions to see which TableCoords are taken
        $winpos = WinGetPos($windows[$Key][0])
        if @error Then
            
        Else
            for $y = 0 to 5
                if $winpos[0] = $TableCoords[$y][0] And $TableCoords[$y][1] = $winpos[1] then
                    $TableCoordsOpen[$y] = 0;
                    ;ConsoleWrite("Coords Taken pre:" & $y & @CRLF)
                EndIf   
            Next
                
        EndIf
         
        $x=0
        While $x < UBound($Tables)
            if stringinstr($Tables[$x],$windows[$Key][0]) Then
            _ArrayDelete($Tables, $x)
            EndIf
            $x = $x+1
        Wend
    EndIf
  Next

$i = 0
While $i < UBound($Tables)
    $tblfound = StringRegExp($Tables[$i], $TitleText)
    If $tblfound == 0 Then
        _ArrayDelete($Tables, $i) ;Remove entries that don't match our TitleText
    EndIf
    $i = $i + 1
WEnd

;Make a new array with the actual available Tables and remove the first 9 characters as they represent some kind of ID
$Tables2 = _ArrayTrim($Tables, 9, 0,0)

;As the bring ListBox is still open and the cursor is now at the very bottom, we need to move it to the first entry
;That's why we need the $firstrun variable for the loop below
Send("{HOME}")

$x = 0
$firstrun = 0
$tablefound = 0
While $x < UBound($Tables)
    While $tablefound = 0
        If $firstrun = 1 Then
            Send("{DOWN}")
        EndIf
        $firstrun = 1
        $var = ControlCommand("Select Remote Window", "", 1005, "GetCurrentSelection", "")
        ;ConsoleWrite("if " & $Tables[$x] & "in" & $var & @CRLF)
        If StringInStr($var, $Tables[$x]) Then
            Send("{ENTER}")
            WinWaitActive($Tables[$x])
            $foundspot = 0
            $i = 0
            while $foundspot = 0
                if $TableCoordsOpen[$i] = 1 then
                    WinMove($Tables[$x], "", $TableCoords[$i][0], $TableCoords[$i][1])
                    $TableCoordsOpen[$i] = 0
                    ;ConsoleWrite("Coords Taken post:" & $i & @CRLF)
                    $foundspot = 1;
                EndIf
                $i = $i + 1
            WEnd
            $tablefound = 1
        EndIf
    WEnd
    $x = $x + 1
    If $x < UBound($Tables) Then
        _StartBring($BringExe, $BringPath, $BringHost)
        $tablefound = 0
    EndIf   
WEnd
Edited by fielpo

Share this post


Link to post
Share on other sites
SmOke_N

http://www.autoitscript.com/forum/forum-2/announcement-12-game-bots-and-automation/


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.