Jump to content
Sign in to follow this  
Fi0da

Enabling a HotKey to Start

Recommended Posts

Fi0da

In my studies in AutoItScript, reading about doubt tried to build a countdown as the code below:

I would like to enable a hotkey to start but could not.

Also like to understand how to make restart the timer after 00:00.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Date.au3>

Global $countdown
Global $inicio = 100000
Global $countdown = $inicio
Global $start = TimerInit()
Global $final = 0
Global $fcolour_toggle = True
HotKeySet ("{PgUp}", "IntervalUp")
HotKeySet ("{PgDn}", "IntervalDown")
HotKeySet ("{Pause}","Stop")
;HotKeySet ("{End}","Start")


$hGUI = GUICreate("", 120, 40, @DesktopWidth -1200, 750, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_TOPMOST)
$hLabel = GUICtrlCreateLabel("", 0, 0, 120, 20, BitOr($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-25, 0xFF8000)
GUISetState()


;Func Start()


    While $countdown > 0

$countdown = $inicio - TimerDiff($start)
    Select
        Case $countdown < 30000 And $countdown > 29000
            AdlibRegister("_Colour_Toggle", 250)
        Case $countdown < 60000 And $countdown > 59000
            AdlibRegister("_Colour_Toggle",250)
        Case $countdown < 20000 And $countdown > 19000
            AdlibRegister("_mousemove")
            Sleep (2000)

    EndSelect
    If Int($countdown / 1000) <> $final Then
        $final = Int ($countdown / 1000)
        $countdown = $inicio - TimerDiff($start)
        StarTimer()

    EndIf
;   EndIf
    Sleep(100)


    Sleep (100)
WEnd


Func StarTimer()

    Local $iHours, $iMins, $iSecs
    _TicksToTime($countdown, $iHours, $iMins, $iSecs)
    GUICtrlSetData($hLabel, "Tempo Restante" & " " & $iMins & ":" & StringFormat("%02i", $iSecs))

EndFunc


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _mousemove ()
    MouseMove (400,500)
    Sleep (100)
    EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func _Colour_Toggle()

    $fcolour_toggle = Not $fcolour_toggle
    If $fcolour_toggle Then
        GUICtrlSetBkColor($hLabel, 0xFFFF00)
    Else
        GUICtrlSetBkColor($hLabel, 0xFF8000)
    EndIf

EndFunc


func IntervalUp ()
    $inicio = $inicio *1.1
EndFunc
;

Func IntervalDown ()
    $inicio = $inicio /1.1
EndFunc
;
Func Stop ()
Exit
EndFunc

Thanks For advance for teaching again

I read ... I update ... I'm learning


I read ... I update ... I learn ...

Share this post


Link to post
Share on other sites
ForsakenGod

if you want to let the script wait untill user input you have to just put in an loop to keep the script "alive"

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Date.au3>

Global $countdown
Global $inicio = 100000
Global $countdown = $inicio
Global $start = TimerInit()
Global $final = 0
Global $fcolour_toggle = True
HotKeySet ("{PgUp}", "IntervalUp")
HotKeySet ("{PgDn}", "IntervalDown")
HotKeySet ("{Pause}","Stop")
HotKeySet ("{End}","Start")


$hGUI = GUICreate("", 120, 40, @DesktopWidth -1200, 750, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_TOPMOST)
$hLabel = GUICtrlCreateLabel("", 0, 0, 120, 20, BitOr($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-25, 0xFF8000)
GUISetState()


While 1
    Sleep(100)
Wend

Func Start()


    While $countdown > 0

$countdown = $inicio - TimerDiff($start)
    Select
        Case $countdown < 30000 And $countdown > 29000
            AdlibRegister("_Colour_Toggle", 250)
        Case $countdown < 60000 And $countdown > 59000
            AdlibRegister("_Colour_Toggle",250)
        Case $countdown < 20000 And $countdown > 19000
            AdlibRegister("_mousemove")
            Sleep (2000)

    EndSelect
    If Int($countdown / 1000) <> $final Then
        $final = Int ($countdown / 1000)
        $countdown = $inicio - TimerDiff($start)
        StarTimer()

    EndIf
;   EndIf
    Sleep(100)


    Sleep (100)
WEnd
EndFunc


Func StarTimer()

    Local $iHours, $iMins, $iSecs
    _TicksToTime($countdown, $iHours, $iMins, $iSecs)
    GUICtrlSetData($hLabel, "Tempo Restante" & " " & $iMins & ":" & StringFormat("%02i", $iSecs))
    
EndFunc


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _mousemove ()
    MouseMove (400,500)
    Sleep (100)
    EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func _Colour_Toggle()

    $fcolour_toggle = Not $fcolour_toggle
    If $fcolour_toggle Then
        GUICtrlSetBkColor($hLabel, 0xFFFF00)
    Else
        GUICtrlSetBkColor($hLabel, 0xFF8000)
    EndIf

EndFunc


func IntervalUp ()
    $inicio = $inicio *1.1
EndFunc
;

Func IntervalDown ()
    $inicio = $inicio /1.1
EndFunc
;
Func Stop ()
Exit
EndFunc

Edit 1 : You were missing endfunc

Edited by ForsakenGod

Share this post


Link to post
Share on other sites
Fi0da

Ok...ill try at home...

And the question about restart the countdown after 00:00 ?

Tkx for reply


I read ... I update ... I learn ...

Share this post


Link to post
Share on other sites
Fi0da

Ok...it works when i press "End"...

Now i wass read about the Automate Restart Countdow but not success .

Anny reply is wellcome :idea:

Edited by Fi0da

I read ... I update ... I learn ...

Share this post


Link to post
Share on other sites
Fi0da

Hello....

I Wass tryed this...

Case $countdown < 10000 And $countdown > 9900
            Call ("StarTimer")
            Sleep (100)

But not run...I duno how to do the timer restart.:idea:

Anny Idea..someone????


I read ... I update ... I learn ...

Share this post


Link to post
Share on other sites
Fi0da

No one?


I read ... I update ... I learn ...

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.