|     Inicio    |   |         |  |   FOROS      |  |      |      
   Elastix - VoIP B4A (Basic4Android) App inventor 2 PHP - MySQL
  Estación meteorológica B4J (Basic4Java) ADB Shell - Android Arduino
  Raspberry Pi Visual Basic Script (VBS) FireBase (BD autoactualizable) NodeMCU como Arduino
  AutoIt (Programación) Visual Basic Cosas de Windows Webs interesantes
Translate:
Búsqueda en este sitio:


.

Autoit en español
Aplicaciones con Autoit - Juan Antonio Villalpando

-- Tutorial de iniciación a Autoit --

Volver al índice del tutorial

____________________________

33.- Temporizador. TimerInit. TimerDiff .

- Vamos a ver ejemplos de temporizadores obtenido de los foros.

_______________________________________________
1.- Temporizador visible.

- https://www.autoitscript.com/forum/topic/81919-setting-up-a-timer/

- En el código escribe un número de minutos, por ejemplo: 2.

- Mediante ToolTip saldrá una ventanita en la parte superior derecha de la pantalla donde irá evolucionando el tiempo.

- Al cabo de los 2 minutos saldrá una Caja de Mensajes indicando la finalización.

Temporizador
				   
$Minutes = 2 ; Esperará 2 minutos.

Local $60Count = 0, $begin = TimerInit()
While $Minutes > $60Count

$dif = TimerDiff($begin)
$dif2 = StringLeft($dif, StringInStr($dif, ".") -1)
$Count = int($dif/1000)
$60Count = Int($Count / 60)

ToolTip("Minutos finales = " & $Minutes & @CRLF & "Minutos pasados = " & $60Count & @CRLF & "Segundos pasados = " & $Count & @CRLF & "Milisegundos pasados = " & $dif2, 20, 20, "Reloj", 1)

Sleep(20)

WEnd

MsgBox(64, "Fin de tiempo,", "Han pasado " & $Minutes & " minutos.")

_______________________________________________
2.- Cuenta atrás.

- https://www.autoitscript.com/forum/topic/127667-how-to-create-a-countdown-timer-in-autoit/

- En el código establecemos: 20000, que son 20 segundos. Comenzará una cuenta atrás.

- Observa que la ventana no tiene el icono de cerrar la aplicación.

Cuenta atrás.
				   
#include <WindowsConstants.au3>

Global $SS_CENTER, $_CompteArebour = 20000, $_Minutes, $_Seconds

$_GuiCountDown = GUICreate("CountDown...", 350, 200, @DesktopWidth/2 -250, @DesktopHeight/2 -100, $WS_EX_TOPMOST)
GUISetBkColor (0xFFFF00)
$TimeLabel = GUICtrlCreateLabel ("", 35, -10, 480, 180, $SS_CENTER)
GUICtrlSetFont ( -1, 50, 800)
GUISetState ()
WinSetOnTop ($_GuiCountDown, "", 1)
$TimeTicks = TimerInit ()

While 1
    _Check ()
    Sleep (200)
WEnd

Func _Check ()
    $_CompteArebour -= TimerDiff ($TimeTicks)
    $TimeTicks = TimerInit ()
    Local $_MinCalc = Int ($_CompteArebour / (60 * 1000)), $_SecCalc = $_CompteArebour - ($_MinCalc * 60 * 1000)
    $_SecCalc = Int ($_SecCalc / 1000)
    If $_MinCalc <= 0 And $_SecCalc <= 0 Then
        GUISetBkColor (0xFF0000, $_GuiCountDown)
        GUICtrlSetData ($TimeLabel, "Bye !")
        Sleep ( 1000 )
        ; If @Compiled Then Shutdown (13)
        Exit
    Else
        If $_MinCalc <> $_Minutes Or $_SecCalc <> $_Seconds Then
            $_Minutes = $_MinCalc
            $_Seconds = $_SecCalc
            GUICtrlSetData ( $TimeLabel, StringFormat ("%02u" & ":" & "%02u", $_Minutes, $_Seconds))
            If $_Minutes = 0 And $_Seconds <= 10 Then
                Beep ( 1200, 100 )
                GUISetBkColor (0xA093FF, $_GuiCountDown)
            EndIf
        EndIf
    EndIf
EndFunc ;==> _Check ()

_______________________________________________
3.- Cuenta atrás.

- https://www.autoitscript.com/forum/topic/38283-how-can-i-make-countdown-timer/

Cuenta atrás.
				   
#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 122, 42, 438, 156)
$Label1 = GUICtrlCreateLabel("02:00", 8, 8, 43, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$time=TimerInit()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    $new = TimerDiff ($time)
    $new = (2*60*1000)-$new
    $seconds = Round ($new/1000)
    $newMin = Floor ($seconds/60)
    $newSec = Mod ($seconds, 60)
    If $newSec < 10 Then $newSec = "0"&$newSec
    GUICtrlSetData ($Label1, $newMin&":"&$newSec)
WEnd

_______________________________________________
4.- Cuenta atrás.

- https://www.autoitscript.com/forum/topic/39209-countdown-timer-help/

Cuenta atrás.
				   
#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("TeaTime", 163, 147, 193, 115)
$Label1 = GUICtrlCreateLabel("5 Minute Tea Timer", 24, 16, 114, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label1 = GUICtrlCreateLabel("5:00", 56, 48, 49, 33)
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("Start", 24, 96, 49, 17, 0)
$Button2 = GUICtrlCreateButton("Exit", 88, 96, 49, 17, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $timer, $bCountdown = False
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button2
            Exit
        Case $Button1
            $bCountdown = True
            $timer = TimerInit()
    EndSwitch
    If $bCountdown Then UpdateTimer()
WEnd

Func UpdateTimer()
    $new = TimerDiff($timer)
    $new = (0.1 * 60 * 1000) - $new
    $seconds = Round($new / 1000)
    $newMin = Floor($seconds / 60)
    $newSec = Mod($seconds, 60)
    If $newSec < 10 Then $newSec = "0" & $newSec
    If $newMin & ":" & $newSec = "0:00" Then $bCountdown = False
    GUICtrlSetData($Label1, $newMin & ":" & $newSec)
EndFunc   ;==>UpdateTimer

_______________________________________________
7.- Reloj.

- https://www.autoitscript.com/forum/topic/149448-timer-example-with-very-low-cpu-use-updated/

Reloj.
				   
#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)


Local $hForm = GUICreate("CounterTimer Sample", 184, 66, -1, 250, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
GUISetOnEvent($GUI_EVENT_CLOSE, "_ExitApp")
Local $Lbl_hour = GUICtrlCreateLabel("0", 16, 20, 40, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateLabel(":", 56, 16, 13, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
Local $Lbl_min = GUICtrlCreateLabel("0", 72, 20, 40, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateLabel(":", 112, 16, 13, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
Local $Lbl_sec = GUICtrlCreateLabel("0", 128, 20, 40, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
Local $Lbl_disc = GUICtrlCreateLabel("Made by gil900", 40, 3, 100, 20, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)

Local $h = 0 , $m = 0 , $s = 0
While 1
    Sleep(1000)
    $s = $s+1
    If $s = 60 Then
        $s = 0
        $m = $m+1
        If $m < 60 Then GUICtrlSetData($Lbl_min,$m)
    EndIf
    If $m = 60 Then
        $m = 0
        $h = $h+1
        GUICtrlSetData($Lbl_min,$m)
        GUICtrlSetData($Lbl_hour,$h)
    EndIf
    GUICtrlSetData($Lbl_sec,$s)
WEnd


Func _ExitApp()
    GUIDelete()
    Exit
EndFunc

_______________________________________________
8.- Cuenta atrás.

- https://www.autoitscript.com/forum/topic/75932-timer/

- Tiene una barra de evolución.

Cuenta atrás.
				   
#include <GUIConstants.au3>
GUICreate("Clock", 210, 100)
$OK_Btn = GUICtrlCreateButton("Start", 10, 10, 70, 25)
$std = GUICtrlCreateInput ("Hours", 90,  10, 50, 25)
$min = GUICtrlCreateInput ("Min", 150,  10, 50, 25)
GuiCtrlCreateLabel(":", 142, 14, 5, 25)
$lab = GUICtrlCreateLabel("Time left: ", 10, 50, 200, 20)
$progressbar1 = GUICtrlCreateProgress (10,70,190,20)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()

    Select

        Case $msg = $GUI_EVENT_CLOSE
            GUIDelete()
            Exit

        Case $msg = $OK_Btn
            if GUICtrlRead($OK_Btn) = "Start" Then
                $time = (StringIsDigit(GUICtrlRead($std)) Or StringIsFloat(GUICtrlRead($std)))* GUICtrlRead($std) * 3600
                $time += (StringIsDigit(GUICtrlRead($min)) Or StringIsFloat(GUICtrlRead($min))) * GUICtrlRead($min) * 60
                GUICtrlSetData ($OK_Btn,"Stop")
                $begin = TimerInit()
                While Int(TimerDiff($begin)/1000) <= $time
                    $Diffhour = Int($time/3600 - TimerDiff($begin)/3600000)
                    $Diffmin = Int(Mod($time/60 - TimerDiff($begin)/60000, 60))
                    $Diffsek = Int(Mod($time - TimerDiff($begin)/1000, 60))
                    GUICtrlSetData($lab, "Time Left: " & $Diffhour & " h " & $DiffMin & " min " & $Diffsek & " sec ")
                    GUICtrlSetData($progressbar1, (Int(TimerDiff($begin)/1000)/$time)*100)
                    if Int(TimerDiff($begin)/1000) = $time then
                        GUICtrlSetData($progressbar1, 100)
                        SoundPlay(@WindowsDir & "\Media\Tada.wav", 1)
                        GUICtrlSetData($progressbar1, 0)
                        GUICtrlSetData ($OK_Btn,"Start")
                        ContinueCase
                    EndIf
                    if GUIGetMsg() = $OK_Btn then
                        GUICtrlSetData($progressbar1, 0)
                        GUICtrlSetData ($OK_Btn,"Start")
                        ContinueCase
                    EndIf
                    Sleep(10)
                WEnd
            ElseIf GUICtrlRead($OK_Btn) = "Stop" Then
                GUICtrlSetData ($OK_Btn,"Start")
            EndIf

        Case @error

    EndSelect

 WEnd

 

Otra versión cuenta atrás.
				   
#include <GUIConstants.au3>

GUICreate("Quick Timer", 210, 115)
$OK_Btn = GUICtrlCreateButton("Start", 10, 25, 70, 25)
$std = GUICtrlCreateInput ( "", 90,  25, 50, 25)
$hidde = GUICtrlCreateInput("", 150, 25, 50, 25)

GuiCtrlCreateLabel("Hours", 90, 10, 50, 15)
GuiCtrlCreateLabel("Minutes", 150, 10, 70, 15)


GuiCtrlCreateLabel(":", 142, 29, 5, 25)
$progressbar1 = GUICtrlCreateProgress (10,85,190,20)
$Minutes = GUICtrlCreateCombo("Minutes  0", 110, 55, 80, 25) ;added zero to keep from erroring out.
GUICtrlSetData(-1, "1 Minutes|3 Minutes|5 Minutes|10 Minutes|15 Minutes|20 Minutes|25 Minutes|30 Minutes|45 Minutes|50 Minutes|59 Minutes")
$Hours = GUICtrlCreateCombo("Hours  0", 10, 55, 65, 25) ;added zero to keep from erroring out.
GUICtrlSetData(-1, "1 Hour|2 Hours|3 Hours|4 Hours|5 Hours|6 Hours|7 Hours|8 Hours|9 Hours")

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()

    Select

        Case $msg = $GUI_EVENT_CLOSE
            GUIDelete()
            Exit

        Case $msg = $OK_Btn
            if GUICtrlRead($OK_Btn) = "Start" Then
    $asminuteResult = StringRegExp(GUICtrlRead($Minutes), '([\+-]*\d+\.*\d*)', 1)
    GUICtrlSetData ($hidde, $asminuteResult[0])

    $ashourResult = StringRegExp(GUICtrlRead($Hours), '([\+-]*\d+\.*\d*)', 1)
    GUICtrlSetData ($std, $ashourResult[0])

                $time = GUICtrlRead($std)*3600+GUICtrlRead($hidde)*60
                GUICtrlSetData ($OK_Btn,"Stop")
                $begin = TimerInit()
                While Int(TimerDiff($begin)/1000) <= $time
                    GUICtrlSetData($progressbar1, (Int(TimerDiff($begin)/1000)/$time)*100)
                    if Int(TimerDiff($begin)/1000) = $time then
                        GUICtrlSetData($progressbar1, 100)
                        SoundPlay(@WindowsDir & "\Media\Tada.wav", 1)
                        GUICtrlSetData($progressbar1, 0)
                        GUICtrlSetData ($OK_Btn,"Start")
                        ContinueCase
                    EndIf
                    if GUIGetMsg() = $OK_Btn then
                        GUICtrlSetData($progressbar1, 0)
                        GUICtrlSetData ($OK_Btn,"Start")
                        ContinueCase
                    EndIf
                WEnd
            ElseIf GUICtrlRead($OK_Btn) = "Stop" Then
                GUICtrlSetData ($OK_Btn,"Start")
            EndIf

        Case @error

    EndSelect

WEnd

 

 

 

_________________

- Mi correo:
juana1991@yahoo.com
- KIO4.COM - Política de cookies. Textos e imágenes propiedad del autor:
© Juan A. Villalpando
No se permite la copia de información ni imágenes.
Usamos cookies propias y de terceros que entre otras cosas recogen datos sobre sus hábitos de navegación y realizan análisis de uso de nuestro sitio.
Si continúa navegando consideramos que acepta su uso. Acepto    Más información