Jump to content

Search the Community

Showing results for tags 'timer'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Location


WWW


Interests

Found 22 results

  1. Hihi guys several hours messing and i still cat figure out why timer wont reset in my func. Func shold loop untill timer difference and then it shold do other things including to reset timer as well. Timer otself works good. after 30seconds it goes to next func. it just dosnt reset timer. Func _Start() While 1 If TimerDiff($hTimer) > 30 * 1000 Then ; Wait for 10 secs $hTimer = 0 $hTimer = TimerInit() Sleep(100) _Image() Sleep(100) _actTimer() Sleep(100) Else MouseClick("Left", $aPos6[0], $aPos6[1], 1) MouseClick("Left", $aPos4[0], $aPos4[1], 1) MouseClick("Left", $aPos5[0], $aPos5[1], 1) MouseClick("Left", $aPos7[0], $aPos7[1], 150,0) Sleep(100) EndIf WEnd EndFunc
  2. I want to do something , after wait 2 min and again do same thing But I do do not want with sleep, it must be timer How I do this ?
  3. Howdy All I've gone around and around in circles wasting hours trying to fix this problem to no avail so I thought I would try posting for help given there are some real smart people in this forum. Background I have 5 separate .au3 scripts that all do different basic tasks. For example: 1.au3 = opens Chrome browser to obtain information from a specific website then closes 2.au3 = opens an Excel workbook to run a macro then saves and closes 3.au3 = Open two seperate workbooks and transfers data from one to the other then saves and closes 4.au3 = .......etc 5.au3 = .......etc These 5 separate scripts, doing completely different tasks, need to each run once per day at 5 different designated times within a day and then close. For example: 1.au3 = 10am 2.au3 = 12pm 3.au3 = 2pm 4.au3 = 4pm 5.au3 = 5pm Problem I can not get these different scripts to reliably run at their designated times. When I manually run these scripts individually by using 'Go F5' they work perfectly. If I convert these scripts to an .exe and manually run each one they work about 98% of time. How can I schedule these different .au3 files or associated .exe files to reliably run each day at different times? Attempts To Fix The Issue 1. I have tried converting each .au3 script into their own .exe file and use Window's Task Scheduler to run these .exe files at their designated time but the success rate of running each .exe in full, to completion, without error is very low at about 30%. Things that commonly go wrong include a browser not opening but movement still continues on the desk top. Other times things just do not happen at all. 2. I have Windows 7 64 bit and have tried creating and running both (x86) and (x64) .exe files but again reliability problems exist; 3. I have also tried moving each .exe file to the My Documents folder as I read someone that keeping your files on your desktop ties your files to individual Windows user profiles which can cause AutoIt operating errors. Not sure if this is correct but thought I would try it anyway. It did not fix my issue. 4. I installed a program called AlwaysUp which supposedly always reliably runs in the background and will reliably execute your AutoIt script or .exe files. Still have significant reliability issues. Therefore, can someone please provide advice on how I can get my 5 different .au3 files to run at 5 designated times through the day, every day, without fail? Overtime I will be creating more and more different .au3 files to run certain tasks throughout the day and do not want to create one large AutoIt file that continually runs and attempts to do all the different tasks itself. Any help is very appreciated. Thanks Dan
  4. 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
  5. 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
  6. 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.
  7. 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.
  8. 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
  9. Hi all, I am looking for a quick tip on why my autoit script crashes when I run a timer. Currently I have this code: ....(more code above this).... Case $button2 function1() Case $butTimer _Timer_setTimer($hGUI, 3200, "_timedout") ...... Func _timedout() Msgbox(0, "Timed out", "Time is up!") Endfunc When the button is pressed, my timer starts, correct? It doesnt seem to matter if I have it on button activation or not, after the time goes by for a bit, it crashes. Seemingly when the time is up, my script crashes. Thanks for your help!
  10. Hello, i havê been reading, and thinking.. Im on my tablet só i WLL try explain what im trying to do.... Will havê an GUI with 8 timer input that havê to set timer, but wen our if 2 our more ends at some time it havê to run 1, then outher , then outher Timer 1, - input 5 minutes, timer 2 - input 10, timer 3 input 15, timer 4 - input 8,...... At some time, timer 1 will end ate some time of timer 2 / then it at some time will end at some time timer 2 and 3 How i said that wen it happpens first is 2 then 1, then outhers and if 1 is done then 1st is 3, will have more than 9 input boxes that can happen it end at some time, imagine if wen timer 1= 0 function1(), then after end funciona start countdown again, if timer 2 = 0 run function2(), then after end function2 start contdoen again, if both =0 at some time first run 1 then 2, and if wen ends 1, 2,3,4 are =0 :-( :-( :-( im lost This work…??? thank you! Thanks for time, any ideas???
  11. Hello everyone I am encountering a strange problem with timers... i.e wrong time difference . This is an test script made by me to compare Arrays & Maps in terms of speed, I wanted publish the results in my Maps topic, so I am hiding the question in the spoiler to prevent spoilage If you run the script(s), you can see that sometimes the time difference is >1 but the actual difference is almost instantaneous, I don't know what is causing the problem, I think the problem is in my end this time because I used both native and UDF functions and they return identical results... However I spotted something interesting in the documentation for TimerDiff: "Remarks: Some processors are known to cause the function to return incorrect result." Hmmm.... is my processor the culprit? Or is something wrong in my script... Thanks in Advance! TD P.S It was hard to write in the dark spoiler
  12. Hello, just sharing my good old CPU, RAM, TIME widget. CONTY.rar
  13. 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
  14. It's been a long time since I use autoit, and its time to share something and help to someone. Now I just wanna to share something from my work, to contribute to the community. This project is made on request from my friend. Maybe this will help someone to make something else like NewYear countdown #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=blue_shutdown.ico #AutoIt3Wrapper_Outfile=Auto ShutDown.Exe #AutoIt3Wrapper_Res_Description=Auto Shutdown for PC #AutoIt3Wrapper_Res_Fileversion=1.1 #AutoIt3Wrapper_Res_LegalCopyright=Boris Kerkez - boriskerkez@hotmail.com #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; AutoIt Version: 3.3.12.0 #include <Constants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <Timers.au3> ; BUG: ako drzis pritisnut taster(broj) i stisnes ENTER moguce je da ce $Button1 ostati NEAKTIVAN posto $input1, $input1 su prazni ; Ako se vreme na PC promeni u toku tajmera, on to nece registrovati zato sto on odbrojava a ne proverava svake sekunde HH:MM Opt("TrayMenuMode", 1) Global $hGUI, $Active = 0, $FirstTime = 1 Global $remaining_min, $remaining_sec Global $timer_countdown, $calc_option = 1, $readInp_H, $readInp_M, $readInp_after_M $appTitle = "Auto ShutDown v1.1" $gui_w = 280 $gui_h = 150 $hGUI = GUICreate($appTitle, $gui_w, $gui_h) GUISetFont(10, 400, 0, "Verdana") ; Start at $Label1 = GUICtrlCreateLabel("Shutdown at (hh:mm):", 6, 8, 200, 20) $Input1 = GUICtrlCreateInput(@HOUR, 190, 5, 35, 24, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_NUMBER)) GUICtrlSetLimit(-1, 2) $Input2 = GUICtrlCreateInput(@MIN, 240, 5, 35, 24, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_NUMBER)) GUICtrlSetLimit(-1, 2) GUICtrlCreateLabel(":", 230, 8, 5, 20) ; After X minutes $Label2 = GUICtrlCreateLabel("Shutdown after (minutes):", 6, 40, 200, 20) $Input3 = GUICtrlCreateInput("", 190, 39, 85, 24, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_NUMBER)) GUICtrlSetLimit(-1, 6) $Label3 = GUICtrlCreateLabel("", 0, 80, $gui_w, 24, $ES_CENTER) GUICtrlSetFont(-1, 14, 600, 0, "Verdana", 5) GUICtrlSetColor(-1, 0x436EEE) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) ; fix label flickering $Button1 = GUICtrlCreateButton("Set", 5, 120, $gui_w-10, 25, $BS_DEFPUSHBUTTON) GUISetState(@SW_SHOW) While 1 If Not $Active Then Local $memoInp_H = $readInp_H, $memoInp_M = $readInp_M, $memoInp_after_M = $readInp_after_M $readInp_H = GUICtrlRead($Input1) $readInp_M = GUICtrlRead($Input2) $readInp_after_M = GUICtrlRead($Input3) If $memoInp_H <> $readInp_H OR $memoInp_M <> $readInp_M OR $memoInp_after_M <> $readInp_after_M Then ; proveri input1 & input2 + input3(mora biti prazan) | moraju da imaju minimalno 1 cifru (max2 ne treba, postavljen je input limit) | trebaju biti u range-u H=0-23, M=0-59 ; If ( StringLen($readInp_H) < 1 OR $readInp_H < 0 OR $readInp_H > 23 OR StringLen($readInp_M) < 1 OR $readInp_M < 0 OR $readInp_M > 59 AND StringLen($readInp_after_M) = 0 ) Then _Button1StateChange("DISABLE") If ($readInp_H < 0 OR $readInp_H > 23) Then GUICtrlSetData($Input1, "") EndIf If ($readInp_M < 0 OR $readInp_M > 59) Then GUICtrlSetData($Input2, "") EndIf Else If ( StringLen($readInp_after_M) = 0 ) Then $calc_option = 1 ; option: at HH:MM Else ; proveri $Input3 da ne bude 0 i da ne pocinje sa 0 If (StringLeft($readInp_after_M, 1) = 0) Then GUICtrlSetData($Input3, "") _Button1StateChange("DISABLE") Else $calc_option = 2 ; option: after X minutes GUICtrlSetData($Input1, "") GUICtrlSetData($Input2, "") EndIf EndIf _Button1StateChange("ENABLE") EndIf ; ;DEBUG ;ConsoleWrite( $readInp_H &":"& $readInp_M &" | opt:"& $calc_option &" |msec:"& @MSEC & @CRLF) EndIf EndIf ; TRAY msg $tMsg = TrayGetMsg() Switch $tMsg Case $TRAY_EVENT_PRIMARYDOWN _ShowGUI() EndSwitch ; GUI msg $gMsg = GUIGetMsg() Switch $gMsg Case $GUI_EVENT_CLOSE ; Stop the countdown _CountdownStop() Exit Case $GUI_EVENT_MINIMIZE ; Move GUI to tray _HideGUI() ; First time message If $FirstTime Then TrayTip($appTitle, $appTitle & " is minimized to the tray. Click on the tray icon here to restore the window.", 10, $TIP_ICONASTERISK) $FirstTime = 0 EndIf Case $Button1 If Not $Active Then _GUI_Ctrls_DISABLE() ; Calculate and register _CalculateRemainingTime() Else _GUI_Ctrls_ENABLE() ; Stop the countdown _CountdownStop() EndIf EndSwitch WEnd Func _ShowGUI() Opt("TrayIconHide", 1) GUISetState(@SW_SHOW) EndFunc Func _HideGUI() Opt("TrayIconHide", 0) GUISetState(@SW_HIDE) EndFunc Func _GUI_Ctrls_ENABLE() GUICtrlSetState($Input1, $GUI_ENABLE) GUICtrlSetState($Input2, $GUI_ENABLE) GUICtrlSetState($Input3, $GUI_ENABLE) GUICtrlSetData($Button1, "Set") $Active = 0 EndFunc Func _GUI_Ctrls_DISABLE() GUICtrlSetState($Input1, $GUI_DISABLE) GUICtrlSetState($Input2, $GUI_DISABLE) GUICtrlSetState($Input3, $GUI_DISABLE) GUICtrlSetData($Button1, "Cancel") $Active = 1 EndFunc Func _Button1StateChange($button1_state = "ENABLE") If $button1_state = "ENABLE" Then If ( GUICtrlGetState($Button1) = 144 ) Then GUICtrlSetState($Button1, $GUI_ENABLE) EndIf Elseif $button1_state = "DISABLE" Then If ( GUICtrlGetState($Button1) = 80 ) Then GUICtrlSetState($Button1, $GUI_DISABLE) EndIf EndIf EndFunc Func _CalculateRemainingTime() Do ; fix bug with milliseconds Until _MSec() <= 999 Switch $calc_option Case 1 ;OPTION: at HH:MM ; ispravi format - dodaj 0 ispred da bude HH:MM If ( StringLen($readInp_H) < 2 ) Then $readInp_H = 0 & $readInp_H EndIf If ( StringLen($readInp_M) < 2 ) Then $readInp_M = 0 & $readInp_M EndIf ; izracunaj preostale minute If ( $readInp_H >= @HOUR ) Then If ( $readInp_H = @HOUR AND $readInp_M < @MIN ) Then $remaining_min = 1440 - ((@HOUR - $readInp_H)*60 + (@MIN - $readInp_M)) ;(24h*60min=1440min) - (H razlika)*60 + (M razlika) ;ConsoleWrite ( " inH = @H AND inM < @M |min:" & $remaining_min &@CRLF) Else $remaining_min = ((@HOUR - $readInp_H)*60 + (@MIN - $readInp_M)) * -1 ;ConsoleWrite ( " inH >= @H |min:" & $remaining_min &@CRLF) EndIf Else $remaining_min = 1440 - ((@HOUR - $readInp_H)*60 + (@MIN - $readInp_M)) ;(24h*60min=1440min) - (H razlika)*60 + (M razlika) ;ConsoleWrite ( " inH < @H |min:" & $remaining_min &@CRLF) EndIf ; konvertuj u sekunde If ($remaining_min = 0) Then $remaining_sec = (60-@SEC) - $remaining_min * 60 Else $remaining_sec = $remaining_min * 60 - @SEC EndIf Case 2 ; OPTION: after X minutes $remaining_sec = $readInp_after_M * 60 - @SEC EndSwitch ; loading string GUICtrlSetData($Label3, "Loading...") ; fix input bug If ( $remaining_sec <= 0 ) Then GUICtrlSetData($Label3, "Don`t hack me bro!") _GUI_Ctrls_ENABLE() Return EndIf ; fix bug with milliseconds $remaining_sec -= 1 ; set timer for countdown function $timer_countdown = _Timer_Settimer($hGUI, 1000, "_Countdown") EndFunc ;==>CalculateRemainingTime Func _CountdownStop() _Timer_KillTimer($hGUI, $timer_countdown) GUICtrlSetData($Label3, "") EndFunc ;==>CountdownStop Func _Countdown($hWnd, $iMsg, $iIDTimer, $iTime) #forceref $hWnd, $iMsg, $iIDTimer, $iTime If $Active Then Local $sec, $min, $hr $sec = Mod($remaining_sec, 60) $min = Mod($remaining_sec / 60, 60) $hr = Floor($remaining_sec / 60 ^ 2) GUICtrlSetData($Label3, "Time left: " & StringFormat("%02i:%02i:%02i", $hr, $min, $sec)) EndIf If $remaining_sec = 300 Then ; 5min TrayTip($appTitle, "Attention: 5 minutes to shudown!", 10, $TIP_ICONEXCLAMATION) Elseif $remaining_sec = 120 Then ;2min TrayTip($appTitle, "Attention: 2 minutes to shudown!", 10, $TIP_ICONEXCLAMATION) Elseif $remaining_sec = 60 Then ;1min TrayTip($appTitle, "Attention: 1 minute to shudown!", 10, $TIP_ICONEXCLAMATION) ElseIf $remaining_sec <= 10 AND $remaining_sec > 0 Then _ShowGUI() GUICtrlSetColor($Label3, 0xEE4000) ElseIf $remaining_sec <= 0 Then _CountdownStop() ;ConsoleWrite("Shutdown " &@MSEC &@CRLF) ;EXECUTE SHUTDOWN Shutdown(1) Exit EndIf $remaining_sec -= 1 EndFunc ;==>Countdown 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 ;==>Msec blue_shutdown.ico Auto ShutDown.rar
  15. Hi all! I am perplexed by something that should be simple. I am trying to make a small timer which will become part of a larger script, but I'm stuck on comparing the 2 times.. When you run the script, you hit OK on a message box, that's when the current system time and day of the year is saved to a variable.. when you hit OK again, the timer is stopped and the date and time are compared. I'm not using Timerinit() because I want the exact system time the timer started, and the exact system time the timer stopped. Then the time is compared and you get the difference. This is easy as long as I am subtracting 10 seconds from 15 seconds, but what if the start timeer got second: 45 and the top timer got second: 12? I'm sure this is cakewalk for anyone that got higher than a C in math, but I didnt. Can anyone shed some light on this for a simpleton like myself? Msgbox(0,"START","Click to start timer") $a = timestamp() Msgbox(0,"START","Click to stop timer") $b = timestamp() compare($a,$b) Func timestamp() 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 @YDay & ':' & @Hour & ':' & @Min & ':' & @Sec & ':' & $sMilliSeconds EndFunc Func compare($start,$stop) $Comp_a = StringSplit($start,":",2) $Comp_b = StringSplit($stop,":",2) $DayDif = $comp_b[0] - $comp_a[0] $HourDif = $comp_b[1] - $comp_a[1] $MinDif = $comp_b[2] - $comp_a[2] $SecDif = $comp_b[3] - $comp_a[3] If $comp_b[4] > $comp_a[4] then $MSecDif = $comp_b[4] - $comp_a[4] else $MSecDif = $comp_a[4] - $comp_b[4] endif Msgbox(0,"hey you, yeah you!", "Elapse Time:" & @CRLF & "Days: " & $DayDif & @CRLF & "Hours: " & $HourDif & @CRLF & "Minutes: " & $MinDif & @CRLF & "Seconds: " & $SecDif & @CRLF & "Miliseconds: " & $MSecDif ) endfunc Thanks in advance!! EDIT: Would this logic work? ;example $start = 45 $stop = 12 $val1 = $Start - 60 ; val1 becomes 15 $Mydiff = $stop + $val1
  16. Simple and generalpurpose stopwatch function the GUI interface is not a "finished product" but a simple example to show how to use the function. ; --- simple example of use --- #include <GUIConstantsEx.au3> $Form1_1 = GUICreate("Stopwatch", 170, 70);, 100, 100) $LapsedTime = GUICtrlCreateLabel(" 00:00:00.0", 10, 10, 200, 25) GUICtrlSetTip(-1, "Lapsed time") GUICtrlSetFont(-1, 18) $Button1 = GUICtrlCreateButton("halt/go", 10, 40, 50, 20) ; go / pause GUICtrlSetTip(-1, "Pause/Unpause counting") $Button2 = GUICtrlCreateButton("clear", 60, 40, 50, 20) ; reset GUICtrlSetTip(-1, "Clears counter and stops") $Button3 = GUICtrlCreateButton("restart", 110, 40, 50, 20) ; restart GUICtrlSetTip(-1, "Clears counter and restarts") GUISetState(@SW_SHOW) Stopwatch(2) ; reset to 0 and stops While 1 $x = Int(Stopwatch() / 100) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ; toggle status (go <-> pause) Stopwatch() ; this reads counter and sets @extended according to actual $paused status Stopwatch(@extended) ; if is paused (@extended = 1) then unpause [Stopwatch(1)] ; if is unpaused (@extended = 0) then pause [Stopwatch(0)] Case $Button2 ; reset to 0 and stop counter Stopwatch(2) Case $Button3 ; reset to 0 and restart counter Stopwatch(3) EndSwitch If $x <> Int(Stopwatch() / 100) Then $totsec = Int(Stopwatch() / 1000) ; ms to sec $hr = Int($totsec / 3600) ; hours $mn = Int(($totsec - ($hr * 3600)) / 60) ; minutes $sc = Int(($totsec - ($hr * 3600) - ($mn * 60))) ; seconds $tn = Int((Int(Stopwatch() / 100) - ($hr * 36000) - ($mn * 600) - ($sc * 10))) ; tenths of a second GUICtrlSetData($LapsedTime, " " & StringFormat("%02s", $hr) & ":" & StringFormat("%02s", $mn) & ":" & StringFormat("%02s", $sc) & "." & StringFormat("%01s", $tn)) EndIf WEnd ; --- end of example --- ; #FUNCTION# (snippet) ========================================================================================================== ; Name...........: Stopwatch ; Description ...: returns the number of milliseconds counted (according to actions requests by caller) ; Syntax.........: Stopwatch([$action]) ; Parameters ....: $action: 0 - pause counting ; 1 - resume counting ; 2 - reset counter to 0 and stops ; 3 - reset counter to 0 and start counting ; 4 - (default) just ruturns actual counting value and status (status in @extended) ; ; Return values .: number of milliseconds in counter ; @extended contains paused status (1 or 0) ; 1 if stopwatch is in pause ; 0 if stopwatch is counting ; ; Author ........: Chimp ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: yes ; =============================================================================================================================== Func Stopwatch($ToggleTo = 4) Static Local $Paused = True Static Local $Stopwatch = 0 Static Local $TotalTime = 0 Switch $ToggleTo Case 0 ; pause counter If $Paused Then SetExtended($Paused) ; $Paused status Return $TotalTime ; already paused, just return current $TotalTime Else $TotalTime += TimerDiff($Stopwatch) $Paused = True SetExtended($Paused) Return $TotalTime EndIf Case 1 ; unpause counter If $Paused Then $Stopwatch = TimerInit() $Paused = False SetExtended($Paused) Return $TotalTime Else SetExtended($Paused) Return $TotalTime + TimerDiff($Stopwatch) EndIf Case 2 ; reset to 0 and pause $Paused = True $TotalTime = 0 SetExtended($Paused) Return $TotalTime Case 3 ; reset to 0 and restart $Paused = False $TotalTime = 0 $Stopwatch = TimerInit() SetExtended($Paused) Return $TotalTime Case 4 ; return status SetExtended($Paused) If $Paused Then Return $TotalTime Else Return $TotalTime + TimerDiff($Stopwatch) EndIf EndSwitch EndFunc ;==>Stopwatch P.S. If you need a finished stopwatch with a nice gui and more functions, take a look to this one by AZJIO
  17. Hello, I have to ask, how many times TimerInit() can be initialized? Lets think I have a subfunc in a script and the TimerInit() in that subfunc will be caled from time to time. Will that timer be destroyed when subfunc returns to mainfunc? If not how can I destroy it by script? Thanks a lot. Greetings Andrew
  18. Here is my wrapper for SetTimer and KillTimer APIs. AutoIt already has its own, but I tried to make it as simple as I could. #include-once Global $g_avSimpleTimers = [[0, 0]] Func TimerSet($vFunction, $uInterval) Local $hFunction = DllCallbackRegister($vFunction, "none", "HWND;UINT;UINT_PTR;DWORD") If ($hFunction = 0) Then Return 0 Local $uTimerId = DllCall("user32.dll", "UINT_PTR", "SetTimer", _ "HWND", 0, _ "UINT_PTR", 0, _ "UINT", $uInterval, _ "ptr", DllCallbackGetPtr($hFunction))[0] If ($uTimerId = 0) Then DllCallbackFree($hFunction) Return 0 EndIf ReDim $g_avSimpleTimers[$g_avSimpleTimers[0][0] + 2][2] $g_avSimpleTimers[$g_avSimpleTimers[0][0] + 1][0] = $uTimerId $g_avSimpleTimers[$g_avSimpleTimers[0][0] + 1][1] = $hFunction $g_avSimpleTimers[0][0] += 1 Return $uTimerId EndFunc Func TimerUnset($uTimerId) If ($g_avSimpleTimers[0][0] = 0) Then Return False Local $iCount = $g_avSimpleTimers[0][0] For $i = 1 To $iCount + 1 If ($g_avSimpleTimers[$i][0] = $uTimerId) Then DllCall("user32.dll", "BOOL", "KillTimer", _ "HWND", 0, _ "UINT_PTR", $uTimerId) DllCallbackFree($g_avSimpleTimers[$i][1]) For $j = $i To $iCount - 1 $g_avSimpleTimers[$j][0] = $g_avSimpleTimers[$j + 1][0] $g_avSimpleTimers[$j][1] = $g_avSimpleTimers[$j + 1][1] Next $g_avSimpleTimers[0][0] = $iCount - 1 ReDim $g_avSimpleTimers[$iCount][2] Return True EndIf Next Return False EndFunc Example: #include "Simple Timers.au3" Global $t1 = TimerSet(Foo, 500) Global $t2 = TimerSet("Bar", 1000) MsgBox(0, "", "Check the console.") TimerUnset($t1) MsgBox(0, "", "Check the console again.") TimerUnset($t2) ;Not necessary if you are exiting the script Func Foo($a, $b, $c, $d) ConsoleWrite(">Foo" & @CRLF) EndFunc Func Bar($a, $b, $c, $d) ConsoleWrite("!Bar" & @CRLF) EndFunc Download both UDF and example:
  19. Hello again. First of all, this is a "version 2.0" of the scipt posted at '?do=embed' frameborder='0' data-embedContent>> if you'd like to get the whole picture of this. What I have is a ListView created with GUICtrlCreateListView with, f.ex, columns "a" and "b". The number of items in the ListView will vary all from "0" to "n", all based on the user. In column "a" there will be a string which will decide what function to be run, and in column "b" there will be a value of at what interval the specific function will be ran. In the original script I've used _Timer_SetTimer as a global timer, triggering all functions after another, but now I'd like all the functions to have their own intervals. Is it possible to use _Timer_SetTimer for this, or would it be easier to use another type of timerfunction? Don't know if I'm making any sense in this, so feel free to ask if there's anything I can do to help you help me. Best regards, zvvyt
  20. Hi guys, I have a problem involving measuring the time it takes a program to load. I'm writing a script that launches a program, records the time, and then ends the time when the program is responsive(I.E, you can move the mouse and all the buttons work). Since WinWait wasn't working, I tried using ControlCommand with IsVibible on certain buttons, the problem with this approach is that buttons are visible before they are responsive? What is the best way to go about solving this problem? Should I use getpixelcolor or something? Best, Athos
  21. So I have some timers which I reset periodically, but my problem is that they don't wait for the functions before them to finish and in a strange way reset beforehand. -snip- timerinit doesnt wait the mouseclick and sleep functions to finish
  22. I am trying to write a script that keeps accurate time regardless of how long functions take to preform their actions. I thought this would be pretty straight forward. I use several while loops to keep track of days, hours, mins, and secs. But for some reason it is not working correctly. Global $day, $hour, $min, $sec $time = TimerInit() While 1 ;Main Loop $hour = 0 ;Reset hours While $hour <= 23;Loop while hours is less than 24 hours $min = 0 ;Reset minutes While $min <= 59 ;Loop while minutes is less than 60 minutes $sec = 0 ;Reset seconds While $sec <= 59 ;Loop while seconds is less than 60 seconds $show_sec = $sec $dif = TimerDiff($time) ;checks how many milliseconds has passed since timer start $sec = int($dif/1000) ;counts the seconds sleep(50) ;cpu sleep if $sec <> $Show_Sec then ConsoleWrite($sec&@crlf) WEnd ;End Sec Loop $time = $time + 60 * 1000 ; add one minute to initial time to keep accuracy $min = $min + 1 ;Add 1 minute Consolewrite("!Min: "&$min&@crlf) WEnd ;End Min Loop $hour = $hour + 1 ;Add 1 hour WEnd ;End Hour loop $day = $day + 1 ; Add 1 day WEnd [autoit] For the first minute it goes according to plan but after that For some reason it does not reset the sec to 0 after the first minute. I am sure that this is tied to the $time = $time + 60 *1000 I don't believe that I am adding 60 seconds to the ticks from the init time but this is what the autoit examples show on how to add ticks. Any ideas?
×
×
  • Create New...