SaeidN

Timer

21 posts in this topic

Hi,

I searched a lot here but didn't find what I want. Most of them were countdown and other stuff and back to 2004.

I just want a normal timer that when a button on gui is pressed, it starts from 00:00:00 and goes up.

Share this post


Link to post
Share on other sites



Should be pretty simple with a GUI and an AdlibRegister() function that calls a Func updating the Control in the GUI.
What do you have we can play with?

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
17 minutes ago, Jos said:

Should be pretty simple with a GUI and an AdlibRegister() function that calls a Func updating the Control in the GUI.
What do you have we can play with?

Jos

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 286, 140, 192, 124)
Global $StartBtn = GUICtrlCreateButton("Start", 32, 64, 99, 41)
Global $StopBtn = GUICtrlCreateButton("Stop", 168, 64, 91, 41)
Global $Label1 = GUICtrlCreateLabel("00:00:00", 104, 16, 82, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $StartBtn
            runfunction()
        Case $StopBtn
            
    EndSwitch
WEnd

Func runfunction()
    ;codes here
EndFunc

This is an example of my code. When I click on start btn, is calls a func. and at the same time I want the timer which is 00:00:00 to start.

And when I click on stop, I want both timer and function stop. (without closing gui)

Share this post


Link to post
Share on other sites

I don't see the  AdlibRegister()  function like I suggested so did you open the helpfile and checked it out?
Give it a try and post back what you tried.

Jos

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
25 minutes ago, Jos said:

I don't see the  AdlibRegister()  function like I suggested so did you open the helpfile and checked it out?
Give it a try and post back what you tried.

Jos

Thank you Jos.

I made this and it's working, but since in my function I have loops, so the stop button doesn't work. (I made that while loop a comment)

#include <MsgBoxConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 286, 140, 192, 124)
Global $StartBtn = GUICtrlCreateButton("Start", 32, 64, 99, 41)
Global $StopBtn = GUICtrlCreateButton("Stop", 168, 64, 91, 41)
Global $TimeLabel = GUICtrlCreateLabel("00:00:00", 104, 16, 82, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $StartBtn
            Example()
        Case $StopBtn
            AdlibUnRegister("MyAdLibFunc")
    EndSwitch
WEnd

Func Example()
    AdlibRegister("MyAdLibFunc",1000)
    ;While 1
        ;codes here
    ;WEnd
EndFunc

Func MyAdLibFunc()
    Local Static $iCount = 0
    $iCount += 1
    $sec2time_hour = Int($iCount / 3600)
    $sec2time_min = Int(($iCount - $sec2time_hour * 3600) / 60)
    $sec2time_sec = $iCount - $sec2time_hour * 3600 - $sec2time_min * 60
    $mtime = StringFormat('%02d:%02d:%02d', $sec2time_hour, $sec2time_min, $sec2time_sec)
    _GUICtrlEdit_SetText($TimeLabel, $mtime)
EndFunc

 

Share this post


Link to post
Share on other sites

Anyone know how to get the stop button to work while it's doing the loop?

Thanks

Share this post


Link to post
Share on other sites
12 minutes ago, Jos said:

The stop button works fine with your code.... What is going wrong for you?

Jos

Uncomment the while loop which I have in my code, then stop button doesn't work.

Because I have loops in my func, so it won't work, and I don't know how to get it to work.

Share this post


Link to post
Share on other sites

That's clear ...  so why do you feel you need that loop there?
In case you do need a loop you simply convert the GUI Start/Stop buttons to use  "On Event" mode. See Helpfile for how that works

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

1 hour ago, Jos said:

That's clear ...  so why do you feel you need that loop there?
In case you do need a loop you simply convert the GUI Start/Stop buttons to use  "On Event" mode. See Helpfile for how that works

Jos

#include <MsgBoxConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>

Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 286, 140, 192, 124)
Global $StartBtn = GUICtrlCreateButton("Start", 32, 64, 99, 41)
GUICtrlSetOnEvent(-1, "Example")
Global $StopBtn = GUICtrlCreateButton("Stop", 168, 64, 91, 41)
GUICtrlSetOnEvent(-1, "_Pause")
Global $TimeLabel = GUICtrlCreateLabel("00:00:00", 104, 16, 82, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $StartBtn
            Example()
        Case $StopBtn
            _pause()
    EndSwitch
WEnd

Func _Pause()
    Local Static $bPaused = False
    If $bPaused = True Then
        AdlibRegister("MyAdLibFunc",1000)
        ConsoleWrite( "Unpaused")
    Else
        AdlibUnRegister("MyAdLibFunc")
        ConsoleWrite ("Paused")
    EndIf
    $bPaused = Not $bPaused
    While $bPaused
        Sleep(300)
    WEnd
EndFunc

Func Example()
    AdlibRegister("MyAdLibFunc",250)
    While 1
        ;codes here
    WEnd
EndFunc

Func MyAdLibFunc()
    Local Static $iCount = 0
    $iCount += 1
    $sec2time_hour = Int($iCount / 3600)
    $sec2time_min = Int(($iCount - $sec2time_hour * 3600) / 60)
    $sec2time_sec = $iCount - $sec2time_hour * 3600 - $sec2time_min * 60
    $mtime = StringFormat('%02d:%02d:%02d', $sec2time_hour, $sec2time_min, $sec2time_sec)
    _GUICtrlEdit_SetText($TimeLabel, $mtime)
EndFunc

It's working partially. I wrote that pause func, so it's actually a pause and unpause button. But unpause doesn't work. In the help file it's saying " GUIGetMsg()" is not needed anymore, but I don't know how to remove it. Whole while loop? or just that or ...?

Edited by SaeidN

Share this post


Link to post
Share on other sites

The idea is that your main loop is now located under they GUI ..something like:

#include <MsgBoxConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>

Opt("GUIOnEventMode", 1)
Global $Running = 0

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 286, 140, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
Global $StartBtn = GUICtrlCreateButton("Start", 32, 64, 99, 41)
GUICtrlSetOnEvent(-1, "_Start")
Global $StopBtn = GUICtrlCreateButton("Stop", 168, 64, 91, 41)
GUICtrlSetOnEvent(-1, "_Stop")
Global $TimeLabel = GUICtrlCreateLabel("00:00:00", 104, 16, 82, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    If $Running Then
        ; code to perform when Started
    Else
        ; code to perform when Stopped
    EndIf
WEnd

Func _Stop()
    AdlibUnRegister("MyAdLibFunc")
    $Running = 0
    ConsoleWrite("Stopped")
EndFunc   ;==>_Stop

Func _Start()
    AdlibRegister("MyAdLibFunc", 250)
    $Running = 1
    ConsoleWrite("Started")
EndFunc   ;==>_Start

Func MyAdLibFunc()
    Local Static $iCount = 0
    $iCount += 1
    $sec2time_hour = Int($iCount / 3600)
    $sec2time_min = Int(($iCount - $sec2time_hour * 3600) / 60)
    $sec2time_sec = $iCount - $sec2time_hour * 3600 - $sec2time_min * 60
    $mtime = StringFormat('%02d:%02d:%02d', $sec2time_hour, $sec2time_min, $sec2time_sec)
    _GUICtrlEdit_SetText($TimeLabel, $mtime)
EndFunc   ;==>MyAdLibFunc

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            Exit
        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
            MsgBox($MB_SYSTEMMODAL, "Window Minimized", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
        Case @GUI_CtrlId = $GUI_EVENT_RESTORE
            MsgBox($MB_SYSTEMMODAL, "Window Restored", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
    EndSelect
EndFunc   ;==>SpecialEvents

Jos

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
3 hours ago, Jos said:

That's clear ...  so why do you feel you need that loop there?
In case you do need a loop you simply convert the GUI Start/Stop buttons to use  "On Event" mode. See Helpfile for how that works

Jos

#include <MsgBoxConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>

Opt("GUIOnEventMode", 1)
Global $Running = 0

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 286, 140, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
Global $StartBtn = GUICtrlCreateButton("Start", 32, 64, 99, 41)
GUICtrlSetOnEvent(-1, "_Start")
Global $StopBtn = GUICtrlCreateButton("Stop", 168, 64, 91, 41)
GUICtrlSetOnEvent(-1, "_Stop")
Global $TimeLabel = GUICtrlCreateLabel("00:00:00", 104, 16, 82, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    If $Running Then
        myfunc()
    Else
        Sleep(300)
    EndIf
WEnd

Func myfunc()
    $x=1
    While $x < 10
        ConsoleWrite("Running..." & @CR)
        $x+=1
    WEnd
EndFunc


Func _Stop()
    AdlibUnRegister("MyAdLibFunc")
    $Running = 0
    ConsoleWrite("Stopped")
EndFunc   ;==>_Stop

Func _Start()
    AdlibRegister("MyAdLibFunc", 250)
    $Running = 1
    ;myfunc()
    ConsoleWrite("Started")
EndFunc   ;==>_Start

Func MyAdLibFunc()
    Local Static $iCount = 0
    $iCount += 1
    $sec2time_hour = Int($iCount / 3600)
    $sec2time_min = Int(($iCount - $sec2time_hour * 3600) / 60)
    $sec2time_sec = $iCount - $sec2time_hour * 3600 - $sec2time_min * 60
    $mtime = StringFormat('%02d:%02d:%02d', $sec2time_hour, $sec2time_min, $sec2time_sec)
    _GUICtrlEdit_SetText($TimeLabel, $mtime)
EndFunc   ;==>MyAdLibFunc

Func _exit()
    Exit
EndFunc

When I add my function which should have loop, the stop button doesn't work.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

5 minutes ago, Jos said:

Posted script works fine here. (Don't add MyFunc() to _Start() !)

Jos

Yeah, that was for test, then I comment it.

When I click on stop, the timer stops, but the console which is myfunc is running. I wans myfunc to pause. untill I press Start or stop button.

Edited by SaeidN

Share this post


Link to post
Share on other sites

Then simply add a test for 

If $Running Then

in your loop to determine whether Stop was pressed of not.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

2 hours ago, Jos said:

Then simply add a test for 

If $Running Then

in your loop to determine whether Stop was pressed of not.

Jos

I put a consolewrite in if running. When I click start, it starts and never stops,

Then I put it in else, when i press f5, it starts and never stops again.

So it's going into the while loop, but only one of them, and doesn't finish. How can I stop it using buttons?

Edited by SaeidN

Share this post


Link to post
Share on other sites
19 minutes ago, Jos said:

Show your code or else it's a guessing game. ;)

Jos

Run the code in post 12. press start, time starts, consolewrite starts. So far it's ok.

Now click on stop, time stops which is ok, but the consolewrite doesn't stop. I want to have that loop, and stop it.

Share this post


Link to post
Share on other sites

So just do as I suggested !  something like this:

#include <MsgBoxConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>

Opt("GUIOnEventMode", 1)
Global $Running = 0

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 286, 140, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
Global $StartBtn = GUICtrlCreateButton("Start", 32, 64, 99, 41)
GUICtrlSetOnEvent(-1, "_Start")
Global $StopBtn = GUICtrlCreateButton("Stop", 168, 64, 91, 41)
GUICtrlSetOnEvent(-1, "_Stop")
Global $TimeLabel = GUICtrlCreateLabel("00:00:00", 104, 16, 82, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    myfunc()
WEnd

Func myfunc()
    $x=1
    While $x < 100
        If $Running Then
            ConsoleWrite("Running..." & @CR)
            $x+=1
        EndIf
        sleep(50)
    WEnd
EndFunc


Func _Stop()
    AdlibUnRegister("MyAdLibFunc")
    $Running = 0
    ConsoleWrite("-Stopped" & @CR)
EndFunc   ;==>_Stop

Func _Start()
    AdlibRegister("MyAdLibFunc", 250)
    $Running = 1
    ;myfunc()
    ConsoleWrite("+Started" & @CR)
EndFunc   ;==>_Start

Func MyAdLibFunc()
    Local Static $iCount = 0
    $iCount += 1
    $sec2time_hour = Int($iCount / 3600)
    $sec2time_min = Int(($iCount - $sec2time_hour * 3600) / 60)
    $sec2time_sec = $iCount - $sec2time_hour * 3600 - $sec2time_min * 60
    $mtime = StringFormat('%02d:%02d:%02d', $sec2time_hour, $sec2time_min, $sec2time_sec)
    _GUICtrlEdit_SetText($TimeLabel, $mtime)
EndFunc   ;==>MyAdLibFunc

Func _exit()
    Exit
EndFunc

Jos

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

4 hours ago, Jos said:

So just do as I suggested !  something like this:

Jos

Sorry, my func is like this. (Contains while loops and some functions) How do I stop this using stop button?

I put """ If $running then ... endif """" in different places to see if it works, but it didn't.

By the way, I put a consolewrite in the first while loop. When I press F5, that goes to consolewrite directly. Any way to prevent that, until I click start?

#include <MsgBoxConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>

Opt("GUIOnEventMode", 1)
Global $Running = 0

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 286, 140, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
Global $StartBtn = GUICtrlCreateButton("Start", 32, 64, 99, 41)
GUICtrlSetOnEvent(-1, "_Start")
Global $StopBtn = GUICtrlCreateButton("Stop", 168, 64, 91, 41)
GUICtrlSetOnEvent(-1, "_Stop")
Global $TimeLabel = GUICtrlCreateLabel("00:00:00", 104, 16, 82, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    ConsoleWrite("test while 1" & @CR)
    myfunc()
WEnd

Func myfunc()
    $x=1
    While 1
        If $Running Then
            ConsoleWrite("func 1 first loop." & @CR)
            Sleep(500)
            While 1
                ConsoleWrite("2nd while loop." & @CR)
                func2()
                Sleep(500)
            WEnd

        EndIf
        sleep(1000)
    WEnd
EndFunc

Func func2()
    ConsoleWrite("this is func 2." & @CR)
    Sleep(500)
EndFunc


Func _Stop()
    AdlibUnRegister("MyAdLibFunc")
    $Running = 0
    ConsoleWrite("-Stopped" & @CR)
EndFunc   ;==>_Stop

Func _Start()
    AdlibRegister("MyAdLibFunc", 250)
    $Running = 1
    ConsoleWrite("+Started" & @CR)
EndFunc   ;==>_Start

Func MyAdLibFunc()
    Local Static $iCount = 0
    $iCount += 1
    $sec2time_hour = Int($iCount / 3600)
    $sec2time_min = Int(($iCount - $sec2time_hour * 3600) / 60)
    $sec2time_sec = $iCount - $sec2time_hour * 3600 - $sec2time_min * 60
    $mtime = StringFormat('%02d:%02d:%02d', $sec2time_hour, $sec2time_min, $sec2time_sec)
    _GUICtrlEdit_SetText($TimeLabel, $mtime)
EndFunc   ;==>MyAdLibFunc

Func _exit()
    Exit
EndFunc

Thanks

Edited by SaeidN

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

  • Similar Content

    • jannikrendl
      By jannikrendl
      Hey guys,
      I would like to create a simple Timer which starts counting down if a key is pressed and after running out of time making a sound. Afterwards it should reset and wait again for the same key to be pressed to start again.
       
      I am new to autoit and really don't know how to get started...
      How I would try to do it:
      while(1) WEnd HotKeySet("{F9}", "_Timer") Func _Timer() ;FUNCTION HERE but I don't know what to do there :& EndFunc Best regards and thanks in advance
       
      JR
    • argumentum
      By argumentum
      I wanted a timer, could not find what I wanted and wrote this. Posted for the next lazy one, like me, copy'n'paste kind of ppl.
      And added an "Alarm", ( at times I need it to trigger at a time and not, in so many minutes )
      Also added an "insist/replay" ( since I'm coding, might as well have the feature )

      #NoTrayIcon #include <TrayConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) ; removes the chance for misspelled variables causing bugs. Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode. Opt("TrayOnEventMode", 1) ; Enable TrayOnEventMode. Opt("GUIOnEventMode", 1) ; OnEvent functions notifications Global $seconds = 0, $g_sec, $g_min, $g_hr, $started = False, $sec = 99, $aTimeHold[3], $g_IsAlarm = 0, $iAppTitle, $sAppTitle = timerTitle() $iAppTitle = @extended #Region ### START Koda GUI section ### Form=\\WDMYCLOUDEX4100\Public\[FMIS]\au3_Shared_projects\timerThing.kxf Global $Form1 = GUICreate($sAppTitle, 245, 74, @DesktopWidth - 275 - (40 * $iAppTitle), 20 + (40 * $iAppTitle), -1, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE)) Global $idHour = GUICtrlCreateInput("00", 5, 4, 49, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) Global $idMin = GUICtrlCreateInput("00", 58, 4, 49, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) Global $idSec = GUICtrlCreateInput("00", 110, 4, 49, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) Global $idStart = GUICtrlCreateButton("Start Timer", 163, 6, 75, 61, $BS_MULTILINE) Global $idTitle = GUICtrlCreateInput("", 4, 40, 129, 28, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_WANTRETURN)) Global $idAlarm = GUICtrlCreateCheckbox("", 137, 53, 17, 19, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_RIGHTBUTTON)) Global $idInsist = GUICtrlCreateCheckbox("", 137, 37, 17, 19, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_RIGHTBUTTON)) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetFont($idHour, 14, 800) GUICtrlSetFont($idMin, 14, 800) GUICtrlSetFont($idSec, 14, 800) GUICtrlSetFont($idStart, 12, 800) GUICtrlSetFont($idTitle, 12, 800) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") GUICtrlSetOnEvent($idStart, "idStartClick") GUICtrlSetOnEvent($idTitle, "idTitleChange") GUICtrlSetOnEvent($idAlarm, "idAlarmEvent") TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "OnTray_PRIMARYDOUBLE") GUICtrlSetTip($idStart, 'press ENTER or click' & @CR & @CR & 'once started, on close,' & @CR & 'will move to the tray area.') GUICtrlSetTip($idHour, 'Hours' & @CR & @CR & 'enter the hours' & @CR & 'and press ENTER') GUICtrlSetTip($idMin, 'Minutes' & @CR & @CR & 'enter the minutes' & @CR & 'and press ENTER') GUICtrlSetTip($idSec, 'Seconds' & @CR & @CR & 'enter the seconds' & @CR & 'and press ENTER') GUICtrlSetTip($idTitle, 'Type a title for this' & @CR & 'timer and press ENTER') GUICtrlSetTip($idAlarm, 'Swap between' & @CR & 'Timer and Alarm' & @CR & 'functionality') GUICtrlSetTip($idInsist, 'Replay the alert' & @CR & 'every 10 sec.' & @CR & 'for 10 min.') ;~ If Not FileGetSize("timerThing.wav") Then FileInstall("timerThing.wav", "timerThing.wav") ; if you wanna include your WAV file Global $hForm1 = WinGetHandle($Form1) Global $idDummy = GUICtrlCreateDummy() Global $aAccelKeys[1][2] = [["{Enter}", $idDummy]] GUISetAccelerators($aAccelKeys) GUICtrlSetOnEvent($idDummy, "On_idDummy") While 1 Sleep(50) If Not $started Then ContinueLoop If $sec = @SEC Then ContinueLoop $sec = @SEC Countdown() WEnd Func Form1Close() If $started Then TraySetState(1) WinSetState($hForm1, "", @SW_HIDE) Else GUIDelete() Exit EndIf EndFunc ;==>Form1Close Func Countdown() ; mod. from https://www.autoitscript.com/forum/topic/135227-simple-counter/?do=findComment&comment=950305 If $g_IsAlarm Then If Int(GUICtrlRead($idHour)) = Int(@HOUR) And Int(GUICtrlRead($idMin)) = Int(@MIN) And Int(GUICtrlRead($idSec)) = Int(@SEC) Then $seconds = -1 Else Return EndIf EndIf $g_sec = Mod($seconds, 60) $g_min = Mod($seconds / 60, 60) $g_hr = Floor($seconds / 60 ^ 2) If $seconds < -3 Then Return TrayToolTip() $seconds -= 1 If $seconds = -2 Then GUICtrlSetState($idInsist, $GUI_DISABLE) If GUICtrlRead($idInsist) = 1 Then $seconds = -5 InsistPlayTheWAV() AdlibRegister("InsistPlayTheWAV", 10000) Else playTheWAV() EndIf Return EndIf If $seconds < -1 Then Return GUICtrlSetData($idHour, StringFormat("%02i", $g_hr)) GUICtrlSetData($idMin, StringFormat("%02i", $g_min)) GUICtrlSetData($idSec, StringFormat("%02i", $g_sec)) EndFunc ;==>Countdown Func playTheWAV() OnTray_PRIMARYDOUBLE() WinActivate($hForm1) If Not FileGetSize(@ScriptDir & "\timerThing.wav") Then SoundSetWaveVolume(25) SoundPlay(@WindowsDir & "\media\tada.wav") Else SoundSetWaveVolume(5) SoundPlay(@ScriptDir & "\timerThing.wav") EndIf EndFunc ;==>playTheWAV Func InsistPlayTheWAV() Local Static $t = 0 If $t = 0 Then $t = TimerInit() playTheWAV() If TimerDiff($t) > 600000 Then AdlibUnRegister("InsistPlayTheWAV") $t = 0 EndIf EndFunc ;==>InsistPlayTheWAV Func TrayToolTip() Local $title = $sAppTitle If GUICtrlRead($idTitle) Then $title = GUICtrlRead($idTitle) TraySetToolTip('' & _ $title & @CR & _ GUICtrlRead($idHour) & ":" & GUICtrlRead($idMin) & ":" & GUICtrlRead($idSec) & @CR & @CR & _ 'Double' & @CR & _ 'Click to' & @CR & _ 'restore' & @CR & @CR & ' ') EndFunc ;==>TrayToolTip Func idStartClick() Local $title = $sAppTitle If GUICtrlRead($idTitle) Then $title = GUICtrlRead($idTitle) WinSetTitle($hForm1, "", $title) $sec = 99 $started = Not $started Switch $started Case True GUICtrlSetData($idStart, StringReplace(GUICtrlRead($idStart), "Start", "STOP")) $seconds = (Int(GUICtrlRead($idHour)) * 60 * 60) + (Int(GUICtrlRead($idMin)) * 60) + Int(GUICtrlRead($idSec)) $aTimeHold[0] = StringFormat("%02i", GUICtrlRead($idHour)) $aTimeHold[1] = StringFormat("%02i", GUICtrlRead($idMin)) $aTimeHold[2] = StringFormat("%02i", GUICtrlRead($idSec)) GUICtrlSetState($idStart, $GUI_FOCUS) GUICtrlSetState($idHour, $GUI_DISABLE) GUICtrlSetState($idMin, $GUI_DISABLE) GUICtrlSetState($idSec, $GUI_DISABLE) GUICtrlSetState($idAlarm, $GUI_DISABLE) Case Else GUICtrlSetData($idStart, StringReplace(GUICtrlRead($idStart), "STOP", "Start")) GUICtrlSetData($idHour, $aTimeHold[0]) GUICtrlSetData($idMin, $aTimeHold[1]) GUICtrlSetData($idSec, $aTimeHold[2]) GUICtrlSetState($idHour, $GUI_ENABLE) GUICtrlSetState($idMin, $GUI_ENABLE) GUICtrlSetState($idSec, $GUI_ENABLE) GUICtrlSetState($idAlarm, $GUI_ENABLE) GUICtrlSetState($idInsist, $GUI_ENABLE) GUICtrlSetState($idStart, $GUI_FOCUS) EndSwitch EndFunc ;==>idStartClick Func On_idDummy() Local $i, $s = ControlGetFocus($hForm1) $i = Int(StringRight($s, 1)) If $s = "Button1" Then Return ControlClick($hForm1, "", "Button1") If StringInStr($s, "Edit") Then Switch $i Case 1, 2, 3 Send("{Tab}") EndSwitch EndIf EndFunc ;==>On_idDummy Func idTitleChange() Local $title = $sAppTitle If GUICtrlRead($idTitle) Then $title = GUICtrlRead($idTitle) WinSetTitle($hForm1, "", $title) EndFunc ;==>idTitleChange Func timerTitle() Local $n, $i = 0 For $n = 1 To 1000 If Not WinExists(" Timer thing [" & $n & "]") Then AutoItWinSetTitle(" Timer thing [" & $n & "]") $i = $n - 1 If 40 * $n > @DesktopHeight - 150 Then $i = 1 Return SetError(0, $i, " Timer " & $n) EndIf Next Return SetError(1, $i, " Timer ???") EndFunc ;==>timerTitle Func OnTray_PRIMARYDOUBLE() TraySetState(2) WinSetState($hForm1, "", @SW_SHOW) EndFunc ;==>OnTray_PRIMARYDOUBLE Func idAlarmEvent() ConsoleWrite('+ Func idAlarmEvent() : ' & GUICtrlRead($idAlarm) & @CRLF) If GUICtrlRead($idAlarm) = 1 Then $g_IsAlarm = 1 GUICtrlSetData($idStart, StringReplace(GUICtrlRead($idStart), "Timer", "Alarm")) $sAppTitle = StringReplace($sAppTitle, "Timer", "Alarm") Else $g_IsAlarm = 0 GUICtrlSetData($idStart, StringReplace(GUICtrlRead($idStart), "Alarm", "Timer")) $sAppTitle = StringReplace($sAppTitle, "Alarm", "Timer") EndIf idTitleChange() EndFunc ;==>idAlarmEvent  
    • argumentum
      By argumentum
      I was looking for something like this, in the forum and my HDD. Bad hair day. Anyway,
      Here is the code
      If Not StringInStr($CmdLineRaw, "/ErrorStdOut") Then Exit MsgBox(262144, @ScriptName, "...please run this example from editor.", 3) #include <Date.au3>; for _EstimatedTime() #include <InetConstants.au3>; for _EstimatedTime_Example_2() ;=============================================================================== ; ; Function Name: _EstimatedTime() ; Description: calculate estimated time of completion ; Parameter(s): $a - holds the data ; $iCurrentCount - Current count ; $iTotalCount - Total count ; Requirement(s): #include <Date.au3> ; Return Value(s): false on incomplete data for assessment ; Author(s): argumentum ; Note(s): read the comments ; ;=============================================================================== Func _EstimatedTime(ByRef $a, $iCurrentCount = "", $iTotalCount = "") If $iCurrentCount & $iTotalCount = "" Then ; initialize $a = "" Dim $a[12] $a[5] = TimerInit() ; handle for TimerDiff() $a[0] = "00:00:00" $a[1] = "00:00:00" $a[2] = _NowCalc() ; starting date and time $a[3] = "" $a[4] = "0" Else If $iTotalCount = 0 Then Return False If $iCurrentCount > $iTotalCount Then $iCurrentCount = $iTotalCount _TicksToTime(Int(TimerDiff($a[5])), $a[6], $a[7], $a[8]) _TicksToTime(Int((TimerDiff($a[5]) / $iCurrentCount) * ($iTotalCount - $iCurrentCount)), $a[9], $a[10], $a[11]) $a[0] = StringFormat("%02i:%02i:%02i", $a[6], $a[7], $a[8]) ; elapsed time $a[1] = StringFormat("%02i:%02i:%02i", $a[9], $a[10], $a[11]) ; estimated total time $a[3] = _DateAdd("s", Int((TimerDiff($a[5]) / $iCurrentCount) * ($iTotalCount) / 1000), $a[2]) ; estimated date and time of completion $a[4] = Int($iCurrentCount / $iTotalCount * 100) ; percentage done EndIf Return True EndFunc ;==>_EstimatedTime _EstimatedTime_Example_1() Func _EstimatedTime_Example_1() ConsoleWrite(@CRLF & "+ Example 1" & @CRLF) ConsoleWrite("elapsed " & @TAB & "estimated" & @TAB & "starting date time " & @TAB & "estimated date time" & @CRLF) ConsoleWrite(" _NowCalc() = " & _NowCalc() & @CRLF) Local $n, $sec = @SEC, $aETTF ; "Estimated Time To Finish" data holder _EstimatedTime($aETTF) ; called with just the data holder to init. it For $n = 1234 To 1 Step -1 Sleep(1) If $sec <> @SEC Then $sec = @SEC _EstimatedTime($aETTF, 1234 - $n, 1234) ConsoleWrite($aETTF[0] & @TAB & $aETTF[1] & @TAB & $aETTF[2] & @TAB & $aETTF[3] & @TAB & $aETTF[4] & @CRLF) EndIf Next _EstimatedTime($aETTF, 1234 - $n, 1234) ConsoleWrite($aETTF[0] & @TAB & $aETTF[1] & @TAB & $aETTF[2] & @TAB & $aETTF[3] & @TAB & $aETTF[4] & @CRLF) ConsoleWrite(" _NowCalc() = " & _NowCalc() & @CRLF) EndFunc ;==>_EstimatedTime_Example_1 _EstimatedTime_Example_2() Func _EstimatedTime_Example_2() ConsoleWrite(@CRLF & "+ Example 2" & @CRLF) ConsoleWrite("elapsed " & @TAB & "estimated" & @TAB & "starting date time " & @TAB & "estimated date time" & @CRLF) ConsoleWrite(" _NowCalc() = " & _NowCalc() & @CRLF) Local $aETTF ; "Estimated Time To Finish" data holder _EstimatedTime($aETTF) ; called with just the data holder to init. it ; Save the downloaded file to the temporary folder. Local $sFilePath = @MyDocumentsDir & "\tempFile.bin" Local $sLink = "http://downloads.sourceforge.net/project/portableapps/PortableApps.com%20Platform/PortableApps.com_Platform_Setup_12.0.5.paf.exe?r=http%3A%2F%2Fsourceforge.net%2Fdirectory%2Fbusiness-enterprise%2Fos%3Awindows%2Ffreshness%3Arecently-updated%2F&ts=1442615522&use_mirror=iweb" ; Download the file in the background with the selected option of 'force a reload from the remote site.' Local $hDownload = InetGet($sLink, $sFilePath, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) ; Wait for the download to complete by monitoring when the 2nd index value of InetGetInfo returns True. Do Sleep(1000) If _EstimatedTime($aETTF, InetGetInfo($hDownload, $INET_DOWNLOADREAD), InetGetInfo($hDownload, $INET_DOWNLOADSIZE)) Then ConsoleWrite($aETTF[0] & @TAB & $aETTF[1] & @TAB & $aETTF[2] & @TAB & $aETTF[3] & @TAB & $aETTF[4] & @CRLF) Else ConsoleWrite(". ") EndIf Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE) ; Retrieve the number of total bytes received and the filesize. Local $iBytesSize = InetGetInfo($hDownload, $INET_DOWNLOADREAD) Local $iFileSize = FileGetSize($sFilePath) ; Close the handle returned by InetGet. InetClose($hDownload) _EstimatedTime($aETTF, $iBytesSize, $iFileSize) ConsoleWrite($aETTF[0] & @TAB & $aETTF[1] & @TAB & $aETTF[2] & @TAB & $aETTF[3] & @TAB & $aETTF[4] & @CRLF) ConsoleWrite(" _NowCalc() = " & _NowCalc() & @CRLF) ; Display details about the total number of bytes read and the filesize. ConsoleWrite("The total download size: " & $iBytesSize & " - The total filesize: " & $iFileSize & @CRLF) ; Delete the file. FileDelete($sFilePath) EndFunc ;==>_EstimatedTime_Example_2  
    • IamKJ
      By IamKJ
      I am trying to allow the GUI to gather info as to when to execute a function.  I am having trouble doing this.  So far this is what I have.
       
      ;Timer Func timer () If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(36,"Timer","Please format your answer in 00:00:00:000") Select Case $iMsgBoxAnswer = 6 ;Yes Global $infotime = InputBox ('Time', 'What time to execute?') Do $rawtimer = ToolTip(@Hour & ':' & @Min & ':' & @Sec & ':' & _MSec()) until $rawtimer = $infotime if $rawtimer = $infotime Then msgbox (0,'Worked','Worked') Else EndIf Case $iMsgBoxAnswer = 7 ;No Exit EndSelect EndFunc Func _MSec() Local $stSystemTime = DllStructCreate('ushort;ushort;ushort;ushort;ushort;ushort;ushort;ushort') DllCall('kernel32.dll', 'none', 'GetSystemTime', 'ptr', DllStructGetPtr($stSystemTime)) $sMilliSeconds = StringFormat('%03d', DllStructGetData($stSystemTime, 8)) $stSystemTime = 0 Return $sMilliSeconds EndFunc I have also tried _GUIToolTip_GetText in order to read the tooltip until the time specified, but it still doesn't work.  Any help would be great.
    • Altor
      By Altor
      Hi all.
      I need execute a function at a certain time for example at 00:00 and 12:00.
      My initial idea is use a infinite loop that take the time system and compare with the specified time.
      I do not know if this is the right way to do it. I think this must have occupied the processor for a long time.
      I would appreciate if  comment on whether this is the system that you would use to do this kind of task
      or if you know  any UDF to perform this function.
      Thanks to all