Jump to content

While, For, If, If Not - Debugging


Recommended Posts

What I want:

Whenever the pixel rectangle is red, press start.

Whenever the pixel rectangle is NOT red, press pause.

What Happens:

Whenever the pixel rectangle is red, press start.

Whenever the pixel rectangle is NOT red, I DON'T DO ANYTHING

I have a feeling the issue has to do with some order that things are called in, but I am not sure how to fix it. What do you think?

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

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

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")


;;;;;;;; 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 Then Click_Time_Left_Start (); If it is not the case that the color is not Found, then Start
    Sleep(10)
    If @error Then Click_Time_Left_Pause (); If it is the case that the color is not Found, then Pause
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 Click_Time_Left_Start ()
    While $i = 0
        WinActivate ("TimeLeft Stopwatch")
        Send ("^s");^s Start
        $i = $i + 1
    WEnd
Return
EndFunc

Func Click_Time_Left_Pause ()
    While $i = 0
        WinActivate ("TimeLeft Stopwatch")
        Send ("^p");^p pause
        $i = $i + 1
    WEnd
Return
EndFunc
Link to comment
Share on other sites

shouldnt it be send("^{p}) not just send("^p")

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

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

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")


;;;;;;;; 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 Then Click_Time_Left_Start (); If it is not the case that the color is not Found, then Start
    Sleep(10)
    If @error Then Click_Time_Left_Pause (); If it is the case that the color is not Found, then Pause
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 Click_Time_Left_Start ()
    While $i = 0
        WinActivate ("TimeLeft Stopwatch")
        Send ("^{s})
        $i = $i + 1
    WEnd
Return
EndFunc

Func Click_Time_Left_Pause ()
    While $i = 0
        WinActivate ("TimeLeft Stopwatch")
        send("^{p})
        $i = $i + 1
    WEnd
Return
EndFunc
Edited by thatsgreat2345
Link to comment
Share on other sites

shouldnt it be send("^{p}) not just send("^p")

No that works. But, thanks for the input. I think the problem is in the first While Loop

It seems that if will do Click_Time_Left_Start (), but not Click_Time_Left_Pause ()

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 Then Click_Time_Left_Start (); If it is not the case that the color is not Found, then Start
    Sleep(10)
    If @error Then Click_Time_Left_Pause (); If it is the case that the color is not Found, then Pause
WEnd
Link to comment
Share on other sites

  • Moderators

shouldnt it be send("^{p}) not just send("^p")

'^'

This tells AutoIt to send a CONTROL keystroke, therefore Send("^!a") would send "CTRL+ALT+a".

N.B. Some programs are very choosy about capital letters and CTRL keys, i.e. "^A" is different to "^a". The first says CTRL+SHIFT+A, the second is CTRL+a. If in doubt, use lowercase!

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.

Link to comment
Share on other sites

  • Moderators

Hey Smoke, any feedback on why this script doesn't work properly?

Try this:
#include <IE.au3>
#include <Date.au3>
#include <GUIConstants.au3>

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

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")


;;;;;;;; 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 Then 
        Click_Time_Left_Start (); If it is not the case that the color is not Found, then Start
    Else
        Click_Time_Left_Pause (); If it is the case that the color is not Found, then Pause
    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 Click_Time_Left_Start ()
    $i = 0
    While $i = 0
        WinActivate ("TimeLeft Stopwatch")
        Send ("^s");^s Start
        $i = $i + 1
    WEnd
EndFunc

Func Click_Time_Left_Pause ()
    $i = 0
    While $i = 0
        WinActivate ("TimeLeft Stopwatch")
        Send ("^p");^p pause
        $i = $i + 1
    WEnd
EndFunc

P.S. I don't understand your functions, all they are really doing is this:

Func Click_Time_Left_Start ()
    WinActivate ("TimeLeft Stopwatch")
    Send ("^s");^s Start
EndFunc

Func Click_Time_Left_Pause ()
    WinActivate ("TimeLeft Stopwatch")
    Send ("^p");^p pause
EndFunc
Edited by SmOke_N

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.

Link to comment
Share on other sites

P.S. I don't understand your functions, all they are really doing is this:

Func Click_Time_Left_Start ()
    WinActivate ("TimeLeft Stopwatch")
    Send ("^s");^s Start
EndFunc

Func Click_Time_Left_Pause ()
    WinActivate ("TimeLeft Stopwatch")
    Send ("^p");^p pause
EndFunc
Sweet, it works (for the most part). Thanks. I admit, that I prolly need a few lessons in writing scripts.

1 More question...How do I change the script so that:

Whenever the pixel rectangle is red, press start ONCE, but keep checking for it to turn NOT red.

Whenever the pixel rectangle is NOT red, press pause ONCE, but keep checking for when it does turn red again?

Link to comment
Share on other sites

  • Moderators

Something like this maybe?

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

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

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")


;;;;;;;; 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
        Click_Time_Left_Start (); If it is not the case that the color is not Found, then Start
        $Check = 1
    Else
        If $Check = 1 Then
            Click_Time_Left_Pause (); If it is the case that the color is not Found, then Pause
            $Check = 0
        EndIf
    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 Click_Time_Left_Start ()
    WinActivate ("TimeLeft Stopwatch")
    Send ("^s");^s Start
EndFunc

Func Click_Time_Left_Pause ()
    WinActivate ("TimeLeft Stopwatch")
    Send ("^p");^p pause
EndFunc

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.

Link to comment
Share on other sites

  • Moderators

Hmm... that just made it click start and pause over and over...

Darn it, i can't figure this out!

Sorry... try this:
#include <IE.au3>
#include <Date.au3>
#include <GUIConstants.au3>

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

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")


;;;;;;;; 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
        Click_Time_Left_Start (); If it is not the case that the color is not Found, then Start
        $Check = 1
    ElseIf @error And $Check = 1 Then
        Click_Time_Left_Pause (); If it is the case that the color is not Found, then Pause
        $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 Click_Time_Left_Start ()
    WinActivate ("TimeLeft Stopwatch")
    Send ("^s");^s Start
EndFunc

Func Click_Time_Left_Pause ()
    WinActivate ("TimeLeft Stopwatch")
    Send ("^p");^p pause
EndFunct
Edited by SmOke_N

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.

Link to comment
Share on other sites

Sorry... try this:

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

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

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
;;;;;;;; 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
        Click_Time_Left_Start (); If it is not the case that the color is not Found, then Start
        $Check = 1
    ElseIf @error And $Check = 1 Then
        Click_Time_Left_Pause (); If it is the case that the color is not Found, then Pause
        $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 Click_Time_Left_Start ()
    WinActivate ("TimeLeft Stopwatch")
    Send ("^s");^s Start
EndFunc

Func Click_Time_Left_Pause ()
    WinActivate ("TimeLeft Stopwatch")
    Send ("^p");^p pause
EndFunct

Pure Genius...Thanks! Works Perfectly!

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...