mc83 Posted September 1, 2008 Share Posted September 1, 2008 hi everyone i wrote a script to click a couple of buttons and do some checking on some applicationsthe "nasty" part is that the apps i need to monitor are broadcasted through Citrix, so all i get is an image -no controls to [click on/read from/write to] long story short, i thought it would be nice if I send the data across the network to my colleagues, so i used alek's TCP UDF along with his server & client example scripts (i'm a script kiddie, i know)the actual issue: if I try to close the program while it is running, the console shows "1-> Connected", which means it somehow called _On_Connect().Not long after, the console starts showing "Recursion level has bla bla AutoIt will now close blabla.: Sleep(xx)".========you will not be able to run this because you won't have the citrix-broadcasted apps that i'm monitoringhowever, i hope someone will be able to spot the flaw(s) in my codemany thanks in advanceexpandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <Array.au3> ;~ alek's TCP UDF #include <TCP.au3> ; let's set a couple of options Opt( "MustDeclareVars", 1) ; all variables must be declared before we can use them Opt( "GUIOnEventMode", 1) ; switch to OnEvent mode Opt( "MouseCoordMode", 0) ; mouse coords relative to the active window Opt( "PixelCoordMode", 0) ; pixel coords relative to the active window Opt( "MouseClickDragDelay", 0) ;~ Opt("TrayMenuMode",1) ;~ TrayCreateItem("gigi") Global $working ; the working state Global $tbaWindow = "Train01" ;title of the "To Be Assessed" window Global $tbaPosition ; the position of the "To be Assessed" window Global $tbaScan ;this will hold the overview of "To be Assessed" Global $mTBA, $mNotes, $mNetSpy, $m012 ; used to decide whether or not to check/monitor a particular app Global $mainTimer ; timer to track progress & slow the script down :)) ;~ read the INI values for _numOCR & _getCallRef Global $vHashes = IniReadSection("numDef.ini", "vHashes") Global $hHashes = IniReadSection("numDef.ini", "hHashes") Global $xBIC1 = IniRead("numDef.ini", "xBIC1", "x", 510) Global $xRef = IniReadSection("numDef.ini", "xRef") Global $yRow = IniReadSection("numDef.ini", "yRow") _ArrayDelete($vHashes,0) _ArrayDelete($hHashes,0) _ArrayDelete($xBIC1,0) _ArrayDelete($xRef,0) _ArrayDelete($yRow,0) Global $pColor = "000000" Global $nColor = "FFFFFF" ;~ read the INI values for _getCtrType GLobal $ctrCoords = IniReadSection("Coords.ini", "contractCoords") Global $ctrChecksums = IniReadSection("checksums.ini", "ctrChecksums") For $i=1 To 10 Step +1 Dim $tmp = StringSplit($ctrCoords[$i][1], ",") $ctrCoords[$i][0] = $tmp[1] $ctrCoords[$i][1] = $tmp[2] Next _ArrayDelete($ctrChecksums, 0) ;~ at this point, $ctrCoords[$i][0] = top coord ;~ [1] = bottom coord ;~ and $ctrChecksums[$i][0] = type of line (contract) ;~ [1] = two checksums -> normal + highlighted, separated by a comma Global $checkBIC1s, $checkNotes, $checkNetSpy, $check012, $startPause, $statusLabel ;the GUI controls ;create the GUI GUICreate("clickerV3.b1", 126, 203, 1147, 731, $WS_SYSMENU,$WS_EX_TOPMOST) ;create a group and some checkboxes GUICtrlCreateGroup("Check/monitor", 5, 10, 110, 110) $checkBIC1s = GUICtrlCreateCheckbox("monitor TBA", 15, 30, 90, 20) $checkNotes = GUICtrlCreateCheckbox("refresh Notes", 15, 50, 90, 20) $checkNetSpy = GUICtrlCreateCheckbox("NetworkSpy", 15, 70, 90, 20) $check012 = GUICtrlCreateCheckbox("monitor 012", 15, 90, 90, 20) GUICtrlSetState($checkBIC1s, $GUI_CHECKED) GUICtrlSetState($checkNotes, $GUI_CHECKED) ; we'll disable these two for now... GUICtrlSetState($checkNetSpy, $GUI_DISABLE) GUICtrlSetState($check012, $GUI_DISABLE) $startPause = GUICtrlCreateButton("Start", 5, 130, 60, 40) GUICtrlSetState($startPause, $GUI_FOCUS) $statusLabel = GUICtrlCreateLabel("", 70, 130, 45, 40) GUICtrlSetBkColor($statusLabel, 0xBB0000) ; 0xBB0000 = ~red, 0x008000 = ~green GUISetState() GUISetOnEvent($GUI_EVENT_CLOSE, "_closeClicked") GUICtrlSetOnEvent($startPause, "_toggleWorking") ;~ try to start alek's server If Not _TCP_Server_Start("10.121.1.101", 30213) Then MsgBox(16, "Error!", "Failed to start the server..." & @CRLF & "pls try to re-start the application.") Exit EndIf _TCP_Server_SetOnEvent($Tcp_Server_Event_Open, "_On_Connect") _TCP_Server_SetOnEvent($Tcp_Server_Event_Close, "_On_Close") _TCP_Server_SetOnEvent($Tcp_Server_Event_Recv, "_On_Recv") ;~ on with the main loop While 1 While $working If Not $working Then ExitLoop _testCheckboxes() ; retrieve the state of the checkboxes ; start the main timer $mainTimer = TimerInit() If $mTBA = True Then WinActivate($tbaWindow) ; get rid of "No records found", if present If Hex(PixelGetColor(251, 243),6) = "0000FF" Then Do MouseClick('left', 300, 303, 1, 0) Sleep(50) Until Hex(PixelGetColor(251, 243),6) <> "0000FF" Sleep(100) EndIf ; click "beginScan" until until it really is pressed Do MouseClick("left", 120, 80, 1, 0) Sleep(50) Until PixelChecksum(102,77,171,108) = 1282018304 ; 3548298478 normal ; 1282018304 clicked (scanning) EndIf ; refresh Notes If $mNotes = True Then WinActivate("GlobalAccounts") ;returns 1 if the window is found & activated ; if not found generate some sort of warning, pls! Sleep(100) Send("{F9}") ; sends F9 to Lotus Notes -this refreshes the view EndIf If $mNetSpy = True Then ; check it's source code EndIf Sleep(20000-TimerDiff($mainTimer)) If $mTBA = True Then WinActivate($tbaWindow) If Hex(PixelGetColor(251, 243),6) <> "0000FF" Then $tbaScan = _getOUTdetails() $tbaScan = _parseOUTdetails2String($tbaScan) ConsoleWrite("Sending data... ") _TCP_Server_Send($tbaScan) ConsoleWrite("OK!" & @CRLF) EndIf EndIf Sleep(30000-TimerDiff($mainTimer)) WEnd WEnd ;~ no civillians beyond this point LOL Func _parseOUTdetails2String($raw) ;~ parses the output of _getOUTdetails to into a string that we can send over TCP Local $result = "tbaScan=" For $i = 0 To UBound($raw)-1 $result &= $raw[$i][0] & "&" $result &= $raw[$i][1] & "|" Next $result = StringLeft($result, StringLen($result)-1) Return $result EndFunc Func _getOUTdetails() ;~ the main function that returns an array overview of OUT ;~ elements [$i][0] = call ref and [$i][1] = ctrType Local $overview[10][2] For $i = 0 to 9 Step +1 $overview[$i][1] = _getCtrType($i+1) If ($overview[$i][1] <> "blankROW") Then $overview[$i][0] = _getCallRef($i+1) Next For $i = UBound($overview)-1 To 0 Step -1 If $overview[$i][1] == "blankROW" Or $overview[$i][1] == "False" Then _ArrayDelete($overview, $i) Next Return $overview EndFunc ;~ the _numOCR functions below Func _getCallRef($row) ;~ ===> this function takes $row as an argument -the row to be checked, that is ;~ and it returns the reference number on that row ;~ basically, it runs _numOCR a bunch of times Global $xRef, $yRow, $pColor, $nColor Local $tmp, $result, $mcolor Select Case $row = 1 $mcolor = $nColor Case $row <> 1 $mcolor = $pColor EndSelect For $j = 0 To 6 Step +1 $tmp = _numOCR($xRef[$j][1],$yRow[$row-1][1],$mcolor) ;~ ConsoleWrite("$tmp = _numOCR("&$xRef[$j][1] & ", " & $yRow[$row-1][1] & ", " & $mcolor & ")" & @TAB & @TAB & $tmp & @CRLF) If $tmp == False Then ;do nothing --but if this happens before 6 digits are matched, fuxx it up!!! :D Else $result &= $tmp EndIf Next Return $result EndFunc Func _numOCR($x,$y, $mColor) ;~ ===> numOCR returns the digit matched in the 5x8 px area that "starts" from the $x & $y coordinates ;~ if nothing is matched, it returns False Local $blackPx[5][8] Dim $tmp = 0, $result = False Local $vHash, $hHash ;check to see if colors are in place For $i = 0 To 4 Step +1 For $j = 0 to 7 Step +1 If Hex(PixelGetColor($x+$i, $y+$j), 6) == $mColor Then $blackPx[$i][$j] = 1 Else $blackPx[$i][$j] = 0 EndIf Next Next ;calculate the vertical hash For $i = 0 to 4 Step +1 For $j = 7 to 0 Step -1 $tmp += $blackPx[$i][$j] Next $vHash &= $tmp $tmp = 0 Next ;calculate the horizontal hash For $j = 0 to 7 Step +1 For $i = 4 to 0 Step -1 $tmp += $blackPx[$i][$j] Next $hHash &= $tmp $tmp = 0 Next ;check if we matched any digit For $i=0 To 9 Step +1 If $vHash = $vHashes[$i][1] And $hHash = $hHashes[$i][1] Then $result = $i ExitLoop EndIf Next Return $result EndFunc Func _getCtrType($row) ;~ ===> this function takes $row as an argument -the row to be checked, that is ;~ and it returns either a contract type or "blankROW" (all strings) Local $result = False Local $tmpChecksum = PixelChecksum(481, $ctrCoords[$row][0], 534, $ctrCoords[$row][1]) For $j=0 to UBound($ctrChecksums)-1 Step +1 If(StringInStr($ctrChecksums[$j][1],$tmpChecksum)) Then $result = $ctrChecksums[$j][0] EndIf Next Return $result EndFunc ;~ this bit below can be used to create new checksums ;~ ;~ WinActivate("Train01") ;~ For $i = 0 to 50 Step +1 ;~ $gigi = PixelChecksum(481, $ctrCoords[1][0], 534, $trCoords[1][1]) ;~ ConsoleWrite($gigi & @CRLF) ;~ Next ;~ WinActivate("E:\AutoIt v3\") ;~ server related functions START Func _On_Close($s_Id) ConsoleWrite($s_Id & '->left' & @CRLF) ;Debug, for fun :P EndFunc Func _On_Connect($s_Id) ConsoleWrite($s_Id & '->Connected' & @CRLF) ;Debug, for fun :P EndFunc Func _On_Recv($s_Recv, $s_Id) ConsoleWrite($s_Id & '->message-> ' & $s_Recv & @CRLF) ;Debug, for fun :P ;~ _TCP_Server_Send($s_Recv) EndFunc ;~ server related functions END Func _testCheckboxes() ;~ this tests the checkboxes prior to entering the "work loop" ;~ we need to do this when a loop first starts, otherwise the script might fail ;~ while trying to do a check that requires another one to be done before it Global $mTBA, $mNotes, $mNetSpy, $m012 If Bitand(GUICtrlRead($checkBIC1s),$GUI_CHECKED) = $GUI_CHECKED then $mTBA = True Else $mTBA = False EndIf If Bitand(GUICtrlRead($checkNotes),$GUI_CHECKED) = $GUI_CHECKED then $mNotes = True Else $mNotes = False EndIf If Bitand(GUICtrlRead($checkNetSpy),$GUI_CHECKED) = $GUI_CHECKED then $mNetSpy = True Else $mNetSpy = False EndIf If Bitand(GUICtrlRead($check012),$GUI_CHECKED) = $GUI_CHECKED then $m012 = True Else $m012 = False EndIf EndFunc Func _toggleWorking() If Not $working then _positionWindows() GUICtrlSetBkColor($statusLabel, 0x008000) ; = ~green GUICtrlSetData ($startPause, "Pause") EndIf If $working then GUICtrlSetBkColor($statusLabel, 0xBB0000) ; = ~red GUICtrlSetData ($startPause, "Resume") EndIf $working = Not $working EndFunc Func _positionWindows() ;does the positioning of all the windows on the desktop WinMove($tbaWindow, "", 570, 200) ;change to 0,0 when in production $tbaPosition = WinGetPos($tbaWindow,"") WinMove("GlobalAccounts", "", 0, $tbaPosition[3]-130, $tbaPosition[2], @DesktopHeight - $tbaPosition[3]+102) WinActivate("GlobalAccounts") Local $notesSeparator = PixelSearch(45, 76, 640, 77, 0x000000) If @error <> 1 Then MouseClickDrag("left", $notesSeparator[0], $notesSeparator[1], 25, $notesSeparator[1], 0) ;WinMove("WhatsUp Gold", "", $tbaPosition[2], 0, @DesktopWidth-$tbaPosition[2], @DesktopHeight-28) EndFunc Func _closeClicked() _toggleWorking() Sleep(50) _TCP_Server_Stop() Exit EndFuncCheers! Link to comment Share on other sites More sharing options...
Xenobiologist Posted September 1, 2008 Share Posted September 1, 2008 Hi, please modify your script for testing. We do not have your ini and so on. Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
mc83 Posted September 2, 2008 Author Share Posted September 2, 2008 Hi, thanks for your reply. i don't think the ini files are relevant as they only hold a bunch of coordinates & checksums i am going to include them, but you will still be unable to test this because it only works on the applications i'm connecting to through Citrix (OpenUpTime, Lotus Notes & an IE window) anyhow, here they are: [xRef] ref1 = 54 ref2 = 60 ref3 = 66 ref4 = 72 ref5 = 78 ref6 = 84 ref7 = 90 [xBIC1] x = 510 [yRow] row1 = 161 row2 = 193 row3 = 225 row4 = 257 row5 = 289 row6 = 321 row7 = 353 row8 = 385 row9 = 417 row10= 449 [vHashes] 0=62226 1=11800 2=23334 3=22335 4=23281 5=34334 6=63334 7=14331 8=53335 9=43336 [hHashes] 0=32222223 1=12211111 2=32111115 3=32121123 4=12222511 5=41141123 6=32142223 7=51111111 8=32232223 9=32224123 [ctrChecksums] blankROW = 298129021 BIC1 = 3889757740,4042893683 BIC2 = 2626481979,1685823357 BIC3 = 1190195003,3590954877 BIC4 = 4007128126,4020870527 BMI2 = 781853972,756925273 ARINCDS = 482844300,4099500467 ARINCDC = 1313647232,3288887723 ARINCCS = 1514501543,748925050 ARINCCC = 1579727982,703888799 IER1 = 522803169,2299651383 IER_24fix = 991115775,2444742987 CHARGE = 385268081,2753526689 AR-NONC = 745580419,1462136749 IER-NONC = 1430489505,320297921 BMI-NONC = 731407813,1085031385 BA-NONC = 1918016399,3608242101 [contractCoords] row01 = 161,168 row02 = 193,200 row03 = 225,232 row04 = 257,264 row05 = 289,296 row06 = 321,328 row07 = 353,360 row08 = 385,392 row09 = 417,424 row10 = 449,456 [callRef_coords] #blabla add them here ;-) Thanks, Radu Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now