Jump to content

Constant countdown?


Recommended Posts

Hey there people- Been fiddling around with this for a while now but think I need some help to figure it out. I've simply removed most of the functions just to keep it as short as possibly, but this is what the macro is doing- Sending Keystrokes every XXXX seconds. But how on earth would I make the Timer a Constant countdown rather then update every loop? If at all that is...

AutoItSetOption("MustDeclareVars", 1)
HotKeySet("!1", "Test")
HotKeySet("!2", "Quit")

Dim $i, $Time_Left, $delay, $to, $sleep_i, $time_to_i, $sleep_press, $mindelay, $secs, $Mins, $hours, $secs_Display, $mins_Display, $hours_Display

$to = 10; How many times to Repeate
$sleep_i = 3500; Interval per Repeate
$sleep_press = 50; Sleep per key

while 1
    ToolTip("IDLE...", -1, -1)
    sleep(1000)
WEnd

Func Test()
    ToolTip("SCRIPT STARTING...", -1, -1)
    $i = 0
    $delay = $sleep_i+$sleep_press; Calculate the time.
    $mindelay = 0

    $time_to_i = Round((($delay+$mindelay)*$to)/1000)
    $secs = $time_to_i
    $Mins = Int($secs / 60)
    $hours = Int($Mins / 60)
    $secs_Display = $secs - ($Mins * 60)
    $mins_Display = $Mins - ($hours * 60)
    $hours_Display = $hours - ($Mins * 60)
    
    Do
        ToolTip("Done in : "&$hours&"h "&$mins_Display&"m "&$secs_Display&"s [Done "&$i&" / "&$to&" ("&($to-$i)&" left)]", -1, -1)
        sleep($sleep_i)
        Send("{q down}");Holds the Q key down
        sleep($sleep_press)
        Send("{q up}");Releases the Q key
        
        $time_to_i = Round($time_to_i-(($delay+$mindelay)/1000))
        $secs = $time_to_i
        $Mins = Int($secs / 60)
        $hours = Int($Mins / 60)
        $secs_Display = $secs - ($Mins * 60)
        $mins_Display = $Mins - ($hours * 60)
        $hours_Display = $hours - ($Mins * 60)
        Sleep($mindelay)
        $i = $i + 1
    Until $i = $to
    SoundPlay(@WindowsDir & "\media\tada.wav",1)
EndFunc

Func Quit()
    exit 0
EndFunc

I do know that this code is quite messy and I'am going to clean it up quite abit!

Thanks in advance ^_^

Link to comment
Share on other sites

I'm not totally sure I know what you want. Something like this is simple...

It runs for around 5 seconds, pressing the key 20 times in that period.

$total_time = 5*1000; = 5 seconds
$total_keypress = 20
$current_keypress = 0
$timer = TimerInit()
While 1
    If $current_keypress > $total_keypress Then Exit
    If TimerDiff ($timer) > ($total_time/$total_keypress) Then
        $timer = TimerInit ()
        Send ("A")
        $current_keypress += 1
    EndIf
WEnd
Link to comment
Share on other sites

Ack, Im terribly sorry for not explaining better then I did!

Well, If you run the Script you'll see that it Repeats $to (This is the loop) and $sleep_i + $sleep_press is the actuall delay So that makes up 3550ms per repeate right? So each time the loop is completed it makes a new Tooltip (3550ms per update) appear with the remaining time, this is something I'd wanna see as a constant countdown- The tooltip is in the upper corner between.

Hope that more sense...

EDIT: What is the BB Code for AutoIT Codebox? Did not find that in the help..

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