Jump to content

Debugging While Loop


Recommended Posts

Here is a script that I use 24/7 @ work to automate some tasks. I am having problems with my While Loop. It works perfectly once, then never again, until I close script, then re-open it. Then it will work perfect once, then not again. It checks a pixel to see if it is red or not. If red, it goes to a function. If it is not red, it does another function.

***NOTE***

If the While Loop, and corresponding functions are the only thing in the script, it works perfect always!!! But not with the other functions. The second code is the isolated While loop.

Why do the other functions, screw it up? Can anyone tell me why this only works once?

;small tasks

#include <IE.au3>
#include <Date.au3>
#include <GUIConstants.au3>

Global $Paused, $cat_1, $date_a, $email, $contact, $company, $email, $title, $SysTrayPixel = 0xFF0000, $DLI_Position_X = 974
Global $DLI_Position_y = 753 , $i, $Check = 0, $o_IE

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("^+!{ESC}", "Terminate")
HotKeySet("^q", "Activate_ACT")
HotKeySet("^w", "Activate_Eudora")
HotKeySet("^e", "Activate_Scite")
HotKeySet("^+t", "Activate_AutoIt_Forums")
HotKeySet("^+a", "SendInfo_ACT_ONLY")
HotKeySet("^+s", "SendProposal_ACT_ONLY")
HotKeySet("^1", "Select_ACT_NotesHistory")
HotKeySet("^2", "Select_ACT_Activities")
HotKeySet("^3", "Select_ACT_DailyCalendar")
HotKeySet("^4", "Select_ACT_Contacts")
HotKeySet("^+w", "Select_ACT_WebLink")

HotKeySet ("+!^d", "Add_To_Date")
HotKeySet ("+!^f", "GUI_Time_Slots")
HotKeySet ("+!^y", "BasicEmail")
HotKeySet("^+q", "Return_To_Last_Window")
HotKeySet("!+b", "Choose_BLUE_ACT_Schedule_Activity_Window")
HotKeySet("!+r", "Choose_RED_ACT_Schedule_Activity_Window")
HotKeySet("^!+o", "Open_Work_Stuff")
HotKeySet("+!f", "Follow_Up")
HotKeySet("+!c", "Closing_Call")


;;;;;;;; Body of program would go here;;;;;;;;
While 1
    Opt("WinTitleMatchMode",4)
    Sleep(100)
        $coord = PixelSearch ( $DLI_Position_X - 1 , $DLI_Position_y - 1, _
            $DLI_Position_X, $DLI_Position_y, $SysTrayPixel )   

    If Not @error And $Check = 0 Then
        Sleep(100)
        $current_window_title = WinGetTitle ("active")
        Sleep (4000)
        BlockInput(1)
        Click_Time_Left_Start (); If it is not the case that the color is not Found, then Start
        Sleep (200)
        WinActivate ($current_window_title)
        BlockInput(0)
        $Check = 1
    ElseIf @error And $Check = 1 Then
        Sleep(100)
        $current_window_title = WinGetTitle ("active")
        BlockInput(1)
        Click_Time_Left_Pause (); If it is the case that the color is not Found, then Pause
        $Check = 0
        Sleep (500)
        WinActivate ($current_window_title)
        BlockInput(0)
        $Check = 0
    EndIf
WEnd
;;;;;;;;

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

Func Terminate()
    Exit 0
EndFunc
;********************************************************************************

Func Activate_ACT()
Opt("WinTitleMatchMode",1)
$title = WinGetTitle("")
WinWait("ACT!","")
If Not WinActive("ACT!","") Then WinActivate("ACT!","")
WinWaitActive("ACT!","")
Return
EndFunc


Func Activate_Eudora()
Opt("WinTitleMatchMode",1)
$title = WinGetTitle("")
WinWait("Eudora","")
If Not WinActive("Eudora","") Then WinActivate("Eudora","")
WinWaitActive("Eudora","")
Return
EndFunc

Func Activate_Scite ()
Opt("WinTitleMatchMode",4)
$title = WinGetTitle("")
$scite_window_title = "classname=SciTEWindow"
WinWait($scite_window_title,"")
If Not WinActive($scite_window_title,"") Then WinActivate($scite_window_title,"")
WinWaitActive($scite_window_title,"")
Return
EndFunc

Func Activate_AutoIt_Forums ()
Opt("WinTitleMatchMode",1)
$title = WinGetTitle("")
WinWait("AutoIt Forums","")
If Not WinActive("AutoIt Forums","") Then WinActivate("AutoIt Forums","")
WinWaitActive("AutoIt Forums","")
Return
EndFunc

Func SendInfo_ACT_ONLY ()
Activate_ACT()
Send("!{F9}")
Send("!{F9}")
Send("{CTRLDOWN}t{CTRLUP}")
WinWait("Schedule Activity","")
If Not WinActive("Schedule Activity","") Then WinActivate("Schedule Activity","")
WinWaitActive("Schedule Activity","")
Send("{SHIFTDOWN}s{SHIFTUP}end{SPACE}{SHIFTDOWN}i{SHIFTUP}nfo")
Sleep(500)
Send("{TAB}m{TAB}{TAB}")
Sleep(1000)
Choose_Yellow_ACT_Schedule_Activity_Window ()
Sleep(1000)
Send("{ENTER}")
Return
EndFunc

Func SendProposal_ACT_ONLY ()
Activate_ACT()
Send("!{F9}")
Send("!{F9}")
Send("{CTRLDOWN}t{CTRLUP}")
WinWait("Schedule Activity","")
If Not WinActive("Schedule Activity","") Then WinActivate("Schedule Activity","")
WinWaitActive("Schedule Activity","")
Send("{SHIFTDOWN}s{SHIFTUP}end{SPACE}{SHIFTDOWN}P{SHIFTUP}roposal")
Sleep(500)
Send("{TAB}m{TAB}{TAB}")
Sleep(1000)
MouseMove(707,410)
MouseDown("left")
MouseUp("left")
Sleep(1000)
MouseMove(667,449)
MouseDown("left")
MouseUp("left")
Sleep(1000)
Send("{ENTER}")
Return
EndFunc

Func Select_ACT_NotesHistory ()
Activate_ACT()
Send("+{F9}")
Send("+{F9}")
Return
EndFunc

Func Select_ACT_Activities ()
Activate_ACT()
Send("!{F9}")
Send("!{F9}")
Return
EndFunc

Func Select_ACT_WebLink ()
MouseClick("left", 625,300)
MouseClick("left", 687,379)
Return
EndFunc

Func Select_ACT_DailyCalendar ()
Send("+{F5}")
Return
EndFunc

Func Select_ACT_Contacts ()
Send("{F11}")
Return
EndFunc

Func Click_Time_Left_Start ()
WinWait("TimeLeft Stopwatch","")
If Not WinActive("TimeLeft Stopwatch","") Then WinActivate("TimeLeft Stopwatch","")
WinWaitActive("TimeLeft Stopwatch","")
Sleep (200)
Send ("^s");^s Start
Return
EndFunc

Func Click_Time_Left_Pause ()
WinWait("TimeLeft Stopwatch","")
If Not WinActive("TimeLeft Stopwatch","") Then WinActivate("TimeLeft Stopwatch","")
WinWaitActive("TimeLeft Stopwatch","")
Sleep (200)
Send ("^p");^p pause
Return
EndFunc


Func Add_To_Date ()
#cs
Copy Date
Split String from Copy Date
Save the DD MM YY as 3 sep vars.
Save new var as YY MM DD
Input the amount of days to add
Date Add to YY MM DD 
Save that value
Split STring that value as 3 vars
Save that as $day / $month / $year
Clip put that 
ENter Date into ACT
#ce

;~ Copy Date
Send ("{CTRLDOWN}c{CTRLUP}")
$date_from_ACT = ClipGet ()

;~ Split String from Copy Date
$split_date_ACT = StringSplit( $date_from_ACT, "/");~ Save the DD MM YY as 3 sep vars.

;~ Save new var as YY MM DD
$date_saved_SCITE = $split_date_ACT[3] & "/" & $split_date_ACT[1] & "/" & $split_date_ACT[2]

;~ Input the amount of days to add
$date_input_from_user = InputBox("Date Add", "Enter The Number of Days to Add")
$date_added_from_user = _DateAdd ( 'd', $date_input_from_user, $date_saved_SCITE );~ Date Add to YY MM DD;~ Save that value

;~ Split STring that value as 3 vars
$split_date_added_from_user = StringSplit($date_added_from_user, "/") 

;~ Save that as month / day / year
$date_goes_to_ACT = $split_date_added_from_user[2] & "/" & $split_date_added_from_user[3] & "/" & $split_date_added_from_user[1]

;~ Clip put that 
ClipPut($date_goes_to_ACT)
Send ("{CTRLDOWN}v{CTRLUP}");~ ENter Date into ACT
Sleep (200)
Send ("{TAB}")
Return
EndFunc


;*********************************************************************************
Func BasicEmail();Func to add in basic info for emails
EmailCat_Date ()
Activate_ACT ()
ACT_Copy ()
Activate_Eudora ()
Eudora_Change ()
GUI_Assistant_Me ()
Return
EndFunc


Func EmailCat_Date()
;Make GUI
GUICreate("Input Email Info", 225, 350)
GUISetState(@SW_SHOW)   ; will display an empty dialog box

;Make first Combo Box
$cat_1 = GUICtrlCreateCombo("[Secret]", 10, 35)
GUICtrlSetData(-1, "[Secret]"); Set data in Combo Box

;Second Combo Box
$cat_2 = GUICtrlCreateCombo("[Secret]", 10, 75)
GUICtrlSetData(-1, "[Secret]"); Set data in Combo Box

;Third Combo Box
$cat_3 = GUICtrlCreateCombo("[Secret]", 10, 115)
GUICtrlSetData(-1, "[Secret]"); Set data in Combo Box

;Label for Category
GUICtrlCreateLabel ("Does Email Need A Category?",  10, 10,200,20)

;Make Buttons
$done = GUICtrlCreateButton("Create Email", 35, 275, 150, 50, $BS_DEFPUSHBUTTON)


;Creates a date control for the GUI
; Also, sets the incentive date/expiration date for the last day of the current week, and last day of current month.
$date1 = _DateToDayOfWeek (@YEAR, @MON, @MDAY)
$date2 = 6 - $date1
$date3 = _DateAdd ( "d", $date2, _NowCalcDate())

;Label for the Dates
GUICtrlCreateLabel ("Appointment Date",  10, 210,70,12)
$date_a = GUICtrlCreateDate ($date3, 10,225,200,20 )

GUISetState()   ; will display an empty dialog box
; Run the GUI until the dialog is closed
Do
    $msg = GUIGetMsg()

    If $msg = $done Then
        GUISetState(@SW_HIDE)
        Return
    ;GUI_Assistant_Me() 
    EndIf
        
    If $msg = $cat_1 Then
        GUICtrlRead($cat_1); get the value
        $cat_2 = $cat_1
        $cat_3 = $cat_1
    EndIf
    
    If $msg = $cat_2 Then
        GUICtrlRead($cat_2); get the value
        $cat_1 = $cat_2
        $cat_3 = $cat_2
    EndIf
    
    If $msg = $cat_3 Then
        GUICtrlRead($cat_3); get the value
        $cat_1 = $cat_3
        $cat_2 = $cat_3
    EndIf

    If $msg = $date_a Then
        GUICtrlRead($date_a)
    EndIf

    
Until $msg = $GUI_EVENT_CLOSE
Return
EndFunc

Func ACT_Copy ()
;Copy Company
MouseClick("left", 351,236)

Sleep(300)
Send("{END}")
Sleep (100)
Send ("{SHIFTDOWN}")
Sleep (100)
Send ("{HOME}")
Sleep (100)
Send ("{SHIFTUP}")
Sleep (100)
Send ("{CTRLDOWN}c{CTRLUP}")
Sleep (500)

$company = ClipGet ()
Sleep(200)
;Copy Name
Send("{TAB}")
Send("{END}")
Sleep (100)
Send ("{SHIFTDOWN}")
Sleep (100)
Send ("{HOME}")
Sleep (100)
Send ("{SHIFTUP}")
Sleep (100)
Send ("{CTRLDOWN}c{CTRLUP}")
Sleep (300)
$contact = ClipGet ()
Sleep(200)

;Copy Email
Send("{TAB}")
Sleep (100)
Send("{TAB}")
Sleep (100)
Send("{TAB}")
Sleep (100)
Send("{END}")
Sleep (100)
Send ("{SHIFTDOWN}")
Sleep (100)
Send ("{HOME}")
Sleep (100)
Send ("{SHIFTUP}")
Sleep (100)
Send ("{CTRLDOWN}c{CTRLUP}")
Sleep (300)
$email = ClipGet ()
Return
EndFunc

Func Eudora_Change ()
;Focus on ComboBox with <none>, Assistant, [Secret]-Signature I think
$cat_1A = GUICtrlRead($cat_1)
$date_a_A = GUICtrlRead($date_a)
ControlCommand ("Eudora","","ComboBox3", "SetCurrentSelection", 0)
ControlSetText("Eudora", "", "Edit1", $email)
ControlSetText("Eudora", "", "Edit3", "ATTN: " & $contact)
ControlFocus("Eudora", "", "EudoraEdit1")
$email_body = ControlGetText ( "Eudora", "","EudoraEdit1" )
$AddNotes_New = StringReplace ( $email_body, "NNNNN", $contact)
$AddNotes_NewA = StringReplace ( $AddNotes_New, "XXXXX", $company)
$AddNotes_NewB = StringReplace ( $AddNotes_NewA, "ZZZZZ", $cat_1A);Put Category in Email
$AddNotes_NewC = StringReplace ( $AddNotes_NewB, "[APPOINTMENT DATE]", $date_a_A);Put Category in Add Notes
ControlSetText ( "Eudora", "", "EudoraEdit1", $AddNotes_NewC )

Return
EndFunc

Func GUI_Assistant_Me()
;Make GUI to choose if Email is from Me or Assistant
GUICreate("Email From?", 150, 55)
GUISetState(@SW_SHOW)   ; will display an empty dialog box

$email_assistant = GUICtrlCreateButton("Assistant", 15, 10,50,35, $BS_DEFPUSHBUTTON)
$email_me = GUICtrlCreateButton("Me", 75, 10,50,35)

Do
    $msg = GUIGetMsg()

    If $msg = $email_assistant Then
        PickAssistant()
        Return
    EndIf
        
    If $msg = $email_me Then
        PickMe()
        Return
    EndIf

Until $msg = $GUI_EVENT_CLOSE
Return
EndFunc

Func PickAssistant()
GUISetState(@SW_HIDE)
ControlFocus ( "Eudora", "", "ComboBox3"); do not remove, u need this

ControlCommand ("Eudora","","ComboBox3", "SetCurrentSelection", 1)
;Send("{DOWN}"); do not remove, u need this
ControlClick ( "Eudora", "", "Static2")
Send("{DOWN}")
Send("{DOWN}")
Send("{ENTER}")
ControlFocus("Eudora", "", "EudoraEdit1"); So that you don't accidentally scroll
Return
EndFunc

Func PickMe()
GUISetState(@SW_HIDE)
ControlFocus ( "Eudora", "", "ComboBox3"); do not remove, u need this
ControlCommand ("Eudora","","ComboBox3", "SetCurrentSelection", 2)
Send("{DOWN}{DOWN}"); do not remove, u need this
ControlClick ( "Eudora", "", "Static2")
Send("{DOWN}")
Send("{ENTER}")
ControlFocus("Eudora", "", "EudoraEdit1"); So that you don't accidentally scroll
Return
EndFunc
;***************************************************************************************************

*****************

Func Return_To_Last_Window ()
Opt("WinTitleMatchMode",1)
WinWait($title,"")
If Not WinActive($title,"") Then WinActivate($title,"")
WinWaitActive($title,"")
Return
EndFunc

Func Open_Work_Stuff ()
Run ("C:\Program Files\SciTE\SciTe.exe")
$tmp = "classname=SciTEWindow"
WinWaitActive ($tmp)
    
Run ("C:\Program Files\AutoIt3\AU3Info.exe")
WinWaitActive ("AutoIt v3 Active Window Info")

$Run = FileGetShortName("C:\Program Files\AutoIt3\beta\AutoIt.chm")
Run(@ComSpec & " /c " & $Run, "", @SW_HIDE)
WinWaitActive ("AutoIt Help")

$Temp = FileGetShortName(@MyDocumentsDir & "\Personal\AutoIt")
Run(@ComSpec & " /c Start " & $Temp, "", @SW_HIDE)
    Sleep (2000)
Run ("C:\ACT\act.exe")
WinWaitActive ("ACT")
Run ("C:\Documents and Settings\[Secret]\Eudora\Eudora.exe")
WinWaitActive ("Eudora")



GG_Navigate ()
Sleep (2000)

$i = 0
While $i <= 1
    Run ("C:\Program Files\Internet Explorer\IEXPLORE.EXE"); 4 times
    Sleep (1500)
    $i = $i + 1
WEnd

$Temp = FileGetShortName(@MyDocumentsDir & "\Business")
Run(@ComSpec & " /c Start " & $Temp, "", @SW_HIDE)
Sleep (2000)

Run("Notepad.exe", "", @SW_MAXIMIZE)
Run ("C:\Program Files\Internet Explorer\IEXPLORE.EXE")
Return
EndFunc

Func Choose_Yellow_ACT_Schedule_Activity_Window ()
Opt("WinTitleMatchMode",4)
Opt("MouseCoordMode",1)
WinWait("Schedule Activity","")
If Not WinActive("Schedule Activity","") Then WinActivate("Schedule Activity","")
WinWaitActive("Schedule Activity","")
ControlFocus ( "Schedule Activity", "", "ComboBox4")
Sleep(300)
Send ("m")
Sleep(300)
MouseClick("left", 712,400)
Sleep(300)
MouseClick("left", 663,449); yellow
Return
EndFunc

Func Choose_BLUE_ACT_Schedule_Activity_Window ()
Opt("WinTitleMatchMode",4)
Opt("MouseCoordMode",1)
WinWait("Schedule Activity","")
If Not WinActive("Schedule Activity","") Then WinActivate("Schedule Activity","")
WinWaitActive("Schedule Activity","")
ControlFocus ( "Schedule Activity", "", "ComboBox4")
Sleep(300)
Send ("m")
Sleep(300)
MouseClick("left", 712,400)
Sleep(300)
MouseClick("left", 635,480); BLUE
Return
EndFunc

Func Choose_RED_ACT_Schedule_Activity_Window ()
Opt("WinTitleMatchMode",4)
Opt("MouseCoordMode",1)
WinWait("Schedule Activity","")
If Not WinActive("Schedule Activity","") Then WinActivate("Schedule Activity","")
WinWaitActive("Schedule Activity","")
ControlFocus ( "Schedule Activity", "", "ComboBox4")
Sleep(300)
Send ("h")
Sleep(300)
MouseClick("left", 712,400)
Sleep(500)
MouseClick("Left", 630,445); RED
Return
EndFunc


Func GUI_Time_Slots ()
GuiCreate("MyGUI", 392, 200,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Button_1 = GuiCtrlCreateButton("8:30 Time Slot", 20, 90, 110, 50)
;GUICtrlSetState( -1,$GUI_DEFBUTTON)
$Button_2 = GuiCtrlCreateButton("11:00 Time Slot", 150, 90, 110, 50)
$Button_3 = GuiCtrlCreateButton("1:15 Time Slot", 280, 90, 110, 50)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button_1
        GuiSetState ( @SW_HIDE )
        Sleep (200)
        Time_Slot_830 ()
    
    Case $msg = $Button_2
        GuiSetState ( @SW_HIDE )
        Sleep (200)
        Time_Slot_1100 ()
        
    Case $msg = $Button_3
        GuiSetState ( @SW_HIDE )
        Sleep (200)
        Time_Slot_1315 ()
    
    EndSelect
WEnd
EndFunc

Func Time_Slot_830 ()
    BlockInput (1)
    Sleep (100)
    Send ("0830a")
    BlockInput (0)
    Return
EndFunc

Func Time_Slot_1100 ()
    BlockInput (1)
    Sleep (100)
    Send ("1100a")
    BlockInput (0)
    Return
EndFunc

Func Time_Slot_1315 ()
    BlockInput (1)
    Sleep (100)
    Send ("0115p")
    BlockInput (0)
    Return
EndFunc

Func Follow_Up ()
    Opt("WinTitleMatchMode",4)
    WinWait("Schedule Activity","")
        If Not WinActive("Schedule Activity","") Then WinActivate("Schedule Activity","")
            WinWaitActive("Schedule Activity","")
    ControlFocus ( "Schedule Activity", "", "Edit5")
    Sleep (300)
    Send ("{END}")
    Sleep (100)
    Send ("{SHIFTDOWN}")
    Sleep (100)
    Send ("{HOME}")
    Sleep (100)
    Send ("{SHIFTUP}")
    Sleep (100)
    Send ("Follow Up")
Return  
EndFunc

Func Closing_Call ()
    Opt("WinTitleMatchMode",4)
    WinWait("Schedule Activity","")
        If Not WinActive("Schedule Activity","") Then WinActivate("Schedule Activity","")
            WinWaitActive("Schedule Activity","")
    ControlFocus ( "Schedule Activity", "", "Edit5")
    Sleep (300)
    Send ("{END}")
    Sleep (100)
    Send ("{SHIFTDOWN}")
    Sleep (100)
    Send ("{HOME}")
    Sleep (100)
    Send ("{SHIFTUP}")
    Sleep (300)
    Send ("Closing Call")
Return
EndFunc

Func GG_Navigate ()
    $o_IE = _IECreate ()
    _IENavigate ($o_IE, "http://www.[Secret].com/")
EndFunc

#include <IE.au3>
#include <Date.au3>
#include <GUIConstants.au3>

Global $Paused, $cat_1, $date_a, $email, $contact, $company, $email, $title, $SysTrayPixel = 0xFF0000, $DLI_Position_X = 974
Global $DLI_Position_y = 753 , $i, $Check = 0, $o_IE


;;;;;;;; Body of program would go here;;;;;;;;
While 1
    Opt("WinTitleMatchMode",4)
    Sleep(100)
        $coord = PixelSearch ( $DLI_Position_X - 1 , $DLI_Position_y - 1, _
            $DLI_Position_X, $DLI_Position_y, $SysTrayPixel )   

    If Not @error And $Check = 0 Then
        Sleep(100)
        $current_window_title = WinGetTitle ("active")
        Sleep (4000)
        BlockInput(1)
;       Opt ("CaretCoordMode", 2)
;       $tmp = WinGetCaretPos ()
        Click_Time_Left_Start (); If it is not the case that the color is not Found, then Start
        Sleep (200)
        WinActivate ($current_window_title)
;       Opt ("MouseCoordMode", 2)
;       MouseClick ("left", $tmp[0], $tmp[1])
        BlockInput(0)
        $Check = 1
    ElseIf @error And $Check = 1 Then
        Sleep(100)
        $current_window_title = WinGetTitle ("active")
        BlockInput(1)
;       Opt ("CaretCoordMode", 2)
;       $tmp = WinGetCaretPos ()
        Click_Time_Left_Pause (); If it is the case that the color is not Found, then Pause
        $Check = 0
        Sleep (500)
        WinActivate ($current_window_title)
;       Opt ("MouseCoordMode", 2)
;       MouseClick ("left", $tmp[0], $tmp[1])
        BlockInput(0)
        $Check = 0
    EndIf
WEnd

Func Click_Time_Left_Start ()
WinWait("TimeLeft Stopwatch","")
If Not WinActive("TimeLeft Stopwatch","") Then WinActivate("TimeLeft Stopwatch","")
WinWaitActive("TimeLeft Stopwatch","")
Sleep (200)
Send ("^s");^s Start
Return
EndFunc

Func Click_Time_Left_Pause ()
WinWait("TimeLeft Stopwatch","")
If Not WinActive("TimeLeft Stopwatch","") Then WinActivate("TimeLeft Stopwatch","")
WinWaitActive("TimeLeft Stopwatch","")
Sleep (200)
Send ("^p");^p pause
Return
EndFunc
Link to comment
Share on other sites

Does the loop exit or does it continue to loop the loop, loop???

Add a Else WriteLog("Unknown condidtion") in your loop also make a WriteLog("Loop exit") after your loop.

And probaly do some refactoring in your code

While 1
    Opt("WinTitleMatchMode",4)
    Sleep(100)
        $coord = PixelSearch ( $DLI_Position_X - 1 , $DLI_Position_y - 1, _
            $DLI_Position_X, $DLI_Position_y, $SysTrayPixel )   

    If Not @error And $Check = 0 Then
        Sleep(100)
        $current_window_title = WinGetTitle ("active")
        Sleep (4000)
        CommonCOde($current_window_title)
        $Check = 1
    ElseIf @error And $Check = 1 Then
        Sleep(100)
        $current_window_title = WinGetTitle ("active")
        CommonCode($current_window_title)
        $Check = 0
    Else
        WriteLog("Unknown condition @error;=" & $error & ", $Check;=" & $Check)
    EndIf
WEnd
WriteLog("EXIT LOOP")

Func CommonCode($current_window_title)
        BlockInput(1)
;       Opt ("CaretCoordMode", 2)
;       $tmp = WinGetCaretPos ()
        Click_Time_Left_Start (); If it is not the case that the color is not Found, then Start
        Sleep (200)
        WinActivate ($current_window_title)
;       Opt ("MouseCoordMode", 2)
;       MouseClick ("left", $tmp[0], $tmp[1])
        BlockInput(0)
EndFunc

Just a sugestion anyway.

Link to comment
Share on other sites

Does the loop exit or does it continue to loop the loop, loop???

Add a Else WriteLog("Unknown condidtion") in your loop also make a WriteLog("Loop exit") after your loop.

And probaly do some refactoring in your code

Just a sugestion anyway.

Ty for the feedback. I will give this a try. I am unfamiliar with WriteLog, but I will tinker with it. To answer your question, the loop should always be looping. So, I would like the loop to always check for the red pixel 24/7. The script is always running in the background.

Link to comment
Share on other sites

WriteLog is pseudo code in this case. But you could use the trace udf in my signature and log to dbgview from sysinternals.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...