Jump to content

Running 30 second counter


 Share

Recommended Posts

Hey guys.

I trying to write a script that sends key strokes simulating a counter which goes up in 30 second intervals.

I am having a problem though...When it reaches 00:59:30 I want it to go to 01:00:00 but instead it goes to 00:60:00.

It seems that my statement "If $mins1 = 5 And $mins2 = 9 And $seconds1 = 3 Then" doesn't work. Is this because I am not allowed more than one AND condition?

I have posted my code below...I'm afraid its messy and I am probably doing this in the most stupid way, but then again I don't write programs...ever :(

I hope someone can help me! If you know of a simpler way to do this then please post! For testing purposes I was outputting the key strokes to notepad.exe. To kill the script press ESC.

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


$answer = MsgBox(4, "AutoIt Example (English Only)", "This script will run Notepad type in some text and then quit.  Run?")


Func Terminate()
    Exit 0
EndFunc


If $answer = 7 Then
    MsgBox(0, "AutoIt", "OK.  Bye!")
    Exit
EndIf


; Run Notepad
Run("notepad.exe")


; Wait for the Notepad become active - it is titled "Untitled - Notepad" on English systems
WinWaitActive("[CLASS:Notepad]")

$hours1 = 0
$hours2 = 0
$mins1 = 0
$mins2 = 0
$seconds1 = 0
$seconds2 = 0
$loop = 0
$alt = 0
$minskip = 0

Do

    Send("" & $hours1 & "")
    Send("" & $hours2 & "")
    Send("" & $mins1 & "")
    Send("" & $mins2 & "")
    Send("" & $seconds1 & "")
    Send("" & $seconds2 & "")
    Send("{ENTER}")
    Sleep(50)

        If $mins2 = 9 And $seconds1 = 3 Then
            $mins1 = $mins1 + 1
            $mins2 = 0
            $minskip = 2
        EndIf
        
        If $mins1 = 5 And $mins2 = 9 And $seconds1 = 3 Then
            $mins1 = 0
            $mins2 = 0
            $seconds1 = 0
            $hours2 = $hours2 + 1
            $minskip = 2
        EndIf
                
        If $alt = 0 And $minskip <= 0 Then
            $mins2 = $mins2 + 1
            $alt = $alt + 1
        Else 
            $alt = 0
            $minskip = $minskip - 1
        EndIf
        
        If $seconds1 = 0 Then
            $seconds1 = 3
            Else
            $seconds1 = 0
        EndIf
        
Until $loop = 1
Link to comment
Share on other sites

Try something along the lines of:

While 1
    If $Seconds = 60 Then
        $Minutes += 1
        $Seconds -= 60
        EndIf

    If $Minutes = 60 Then
        $Hours += 1
        $Minutes -= 60
    EndIf
    Sleep(30000) ;30 Seconds
    $Seconds += 30
WEnd

Off topic- It's a pain in the ass to format AU3 code without being in a script... :(

Edited by darkjohn20
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...