Alarma cuenta atrás con AutoIt

Topic created · 4 Mensajes · 1353 Visitas
  • Cierto!! 😄
    Seguí unos tutoriales un poco básicos, si cambias el 0 por un 64, o 54 te suelen salir diferentes tipos de información (critical, question etc)
    La verdad es que es mas rápido que el VB2008, pero para hacer froms es más dificil, por que no puedes modificar desde el FormMaker, tienes que copiar los códigos del form, y pegarlos en el programa, y una vez hecho eso, empezar a ponerle cosas al programa, es lo único que me lia xD

  • Bueno hace no mucho conocí AutoIt ([http://www.autoitscripts.com][0]">[http://www.autoitscripts.com][1]) y la verdad es que me gusta bastante para hacer pequeñas tareas automáticamente. El otro día me hizo falta realizar una tarea tras X minutos y decidí hacer una cuenta atrás para usarla siempre que necesite.

    Y se me ha ocurrido presentaros AutoIt con este programita, que es una cuenta atrás que al finalizar hace sonar una alarma. Pondré el código más adelante, que quiero añadirle más opciones, de momento os dejo que juguéis con el programa:
    [attachment=0]

    #include 
    #include 
    #include 
    #include 
    
    HotKeySet("{ESC}", "Cerrar")
    HotKeySet("{PAUSE}", "Pausa")
    HotKeySet("{F1}", "Ayuda")
    
    Global $alarma=0
    
    Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
    $mainwindow = GUICreate("Cuenta atrás", 300, 100, -1, -1, $WS_POPUP)
    GUISetFont(10, 400, Default, "Comic Sans MS")
    GUISetBkColor(0x80B5F0)
    _GuiRoundCorners($mainwindow, 0, 0, 25, 25)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Cerrar")
    $okbutton = GUICtrlCreateButton("GO!", 230, 60, 50)
    GUICtrlSetOnEvent($okbutton, "GO")
    
    GUICtrlCreateLabel("Tiempo total para la cuenta atrás", 10, 5)
    GUICtrlCreateLabel("Horas:", 10, 25)
    $horas = GUICtrlCreateInput("00", 50, 25, 30, 20)
    GUICtrlCreateLabel("Minutos:", 95, 25)
    $min = GUICtrlCreateInput("00", 145, 25, 30, 20)
    GUICtrlCreateLabel("Segundos:", 190, 25)
    $sec = GUICtrlCreateInput("00", 252, 25, 40, 20)
    
    $restante = GUICtrlCreateLabel(" 00:00:00 ", 100, 60, 80)
    GUICtrlSetFont($restante, 12, 450, "Tahoma")
    $detalles=GUICtrlCreateLabel("ESC para salir. PAUSE para pausar. F1 ver ayuda.", 20, 88)
    GUICtrlSetFont($detalles, 6, 300, "Microsoft Sans Serif")
    
    GUISetState(@SW_SHOW)
    
    While 1
      Sleep(1000)  ; Idle around
    WEnd
    
    Func GO()
      SoundPlay( "beep.wav", 0 )
      
      $h=int(GUICtrlRead($horas))
      $m=int(GUICtrlRead($min))
      $s=int(GUICtrlRead($sec))
      
      $restoS=mod($s, 60)
      $m=$m+( ($s-$restoS)/60 )
      $s=$restoS
      
      $restoM=mod($m, 60)
      $h=$h+( ($m-$restoM)/60 )
      $m=$restoM
      
      ; idea II
      ;$total= $h*60*60 + $m*60 + $s
      ;$inicio = TimerInit()
      ;$final = $inicio + $total*1000
      ;-----------------
      
      GUICtrlSetData($restante, string( StringFormat("%02s",$h) & ":" & StringFormat("%02s",$m) & ":" & StringFormat("%02s",$s) ))
      ;MsgBox(0, "GUI Event", "Al calcular ha quedado: " & StringFormat("%02s",$h) & ":" & StringFormat("%02s",$m) & ":" & StringFormat("%02s",$s))
      
      While $h>0 or $m>0 or $s>0
    	  While $s > 0
    		  Sleep(1000)
    		  $s=$s-1
    		  GUICtrlSetData($restante, string( StringFormat("%02s",$h) & ":" & StringFormat("%02s",$m) & ":" & StringFormat("%02s",$s) ))
    	  Wend
    	  
    	  if $m>0 Then
    		  $m=$m-1
    		  $s=60
    	  ElseIf $h>0 Then
    		  $h=$h-1
    		  $m=59
    		  $s=60
    	  EndIf
      Wend
      
      ;hemos llegado al momento final de la cuenta atras
      accion()
      
      ;$hora = @HOUR & ":" & @MIN & ":" & @SEC & " del " & @MDAY & "/" & @MON
      ;MsgBox(0, "Resultado", "Fin de la cuenta atrás, son las: " & $hora)
    EndFunc
    
    Func Accion()
    	;sonido mientras no se pulse un boton
    	GUICtrlSetFont($restante, 10, 400, "Arial")
    	GUICtrlSetData($restante, "Presione ESC")
    	$alarma=1
    	SoundSetWaveVolume ( 60 ) ; en porcentaje
    	
    	while ($alarma == 1)
    		SoundPlay( "alarma.wav", 0 ) ; 0 indica que el script siga mientras suena la alarma
    		sleep(1500)
    	Wend
    EndFunc
    
    Func Ayuda()
    	;Shellexecute("http://universojuegos.es/");; here's where the action takes place
    	$oIE = _IECreate( "http://foro.universojuegos.es/viewtopic.php?f=68&t=3868" , 0 , 1 )
    EndFunc
    
    Func Pausa()
      MsgBox(4096, "Programa pausado", "El programa está parado." & @LF & " ¿Continuar?")
    EndFunc
    
    Func Cerrar()
    	if ($alarma==1) Then
    		$alarma=0
    		GUICtrlSetFont($restante, 12, 450, "Tahoma")
    		GUICtrlSetData($restante, "00:00:00")
    	Else
    		MsgBox(0, "Salir", "Gracias por usar el programa", 1)
    		Exit
    	EndIf
    EndFunc
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    Func _GuiRoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3)
    ; Round GUI Corners - http://www.autoitscript.com/forum/index.php?s=&showtopic=19370&view=findpost&p=191072
    ; Author - gafrost
       Dim $pos, $ret, $ret2
       $pos = WinGetPos($h_win)
        $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long",  $i_x1, "long", $i_y1, "long", $pos[2], "long", $pos[3], "long", $i_x3,  "long", $i_y3)
       If $ret[0] Then
          $ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $ret[0], "int", 1)
          If $ret2[0] Then
             Return 1
          Else
             Return 0
          EndIf
       Else
          Return 0
      EndIf
      DllClose($ret)
      DllClose($ret2)
    EndFunc ;==>_GuiRoundCorners
    

    [0]: <a href=
    [1]: http://www.autoitscripts.com

  • Bien salva bien ^^
    Yo hace poco también conocí el auto-it, intenté hacer un GM-Tool como el de Yeikel, pero no entendía una mierda de códigos, ni en tutoriales, ni nada por el estilo. Me aburrí de probar y lo dejé, aunque ahora que lo dices voy a bajarlo y así aprobecho y me fijo en algun code.^^

  • Es de lo más sencillo. Por partes:
    1- Descargar: [http://www.autoitscript.com/autoit3/downloads.shtml][0]">[http://www.autoitscript.com/autoit3/downloads.shtml][1]
    [][2]
    2- Una vez instalado abrir el SciTE Script Editor darle código y en Tools->Go probar el script.

    Un código facilote para ir probando:

    MsgBox(0, "Titulo", "Hola Mundo")
    

    Listo, jeje, es difícil hacer un hola mundo más sencillo :icon_mrgreen: (Tools->Go para verlo funcionar)

    En mi programa quiero ponerle dos pestañas, una donde meterle el tiempo de cuenta atrás, es decir lo que tiene ahora, y otra pestaña donde decirle la hora a la que tiene que sonar, y que se encargue él de calcular el tiempo restante.

    [0]: <a href=
    [1]: http://www.autoitscript.com/autoit3/downloads.shtml
    [2]: http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe