Scinner Posted June 22, 2013 Share Posted June 22, 2013 Hi there, how would I go about making a timed event? Lets say I want notepad to open @ HH:MM:SS What command should I look at, preferably with some example code! Thanks guys! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 22, 2013 Moderators Share Posted June 22, 2013 Scinner,I would suggest something with the @HOUR, @MIN & @SEC macros in an If structure. Or _NowCalc with a bit of string manipulation. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Scinner Posted June 22, 2013 Author Share Posted June 22, 2013 Thanks M23! Link to comment Share on other sites More sharing options...
guinness Posted June 22, 2013 Share Posted June 22, 2013 ...and using the Date UDF with AdlibRegister. #include <Constants.au3> #include <Date.au3> Example() Func Example() ; Add 1 minute to the current date and time, then find the difference. Local $iMilliSeconds_Wait = _DateDiff('s', _NowCalc(), _DateAdd('n', 1, _NowCalc())) * 1000 AdlibRegister('OpenNotepad', $iMilliSeconds_Wait) MsgBox($MB_SYSTEMMODAL, '', 'Notepad will open in ' & $iMilliSeconds_Wait & 'ms') While 1 Sleep(250) WEnd EndFunc ;==>Example Func OpenNotepad() AdlibUnRegister('OpenNotepad') Local $iPID = Run('notepad') MsgBox($MB_SYSTEMMODAL, '', 'Notepad is running using the PID: ' & $iPID & @CRLF & @CRLF & _ 'The example will now close.') Exit EndFunc ;==>OpenNotepad UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Scinner Posted July 27, 2013 Author Share Posted July 27, 2013 Im trying this code but it won't work. Can you please help me? #include <GUIConstantsEx.au3> #include <Date.au3> Example() Func Example() Local $Button_1, $msg GUICreate("Timed Notepad Launcher", 300, 40) Opt("GUICoordMode", 1) GuiCtrlCreateLabel("Time:", 10, 10) $tid = GuiCtrlCreateInput("00:00:00", 40, 7, 50, 20) $Button_1 = GUICtrlCreateButton("Launch Notepad @ Set Time", 100, 5, 150) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 If $tid = _NowTime(5) Then Run ("Notepad") EndIf EndSelect WEnd EndFunc ;==>Example Link to comment Share on other sites More sharing options...
Developers Jos Posted July 27, 2013 Developers Share Posted July 27, 2013 (edited) You are not getting the value from the Control but are comparing to it's Handle. Look at GuiCtrlRead() Jos Edited July 27, 2013 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Scinner Posted July 27, 2013 Author Share Posted July 27, 2013 You are not getting the value from the Control but are comparing to it's Handle. Look at GuiCtrlRead() Jos This wont work either? #include <GUIConstantsEx.au3> #include <Date.au3> Example() Func Example() Local $Button_1, $msg, $tid, $menutext, $GUI_EVENT_CLOSE GUICreate("Timed Notepad Launcher", 300, 40) Opt("GUICoordMode", 1) GuiCtrlCreateLabel("Time:", 10, 10) $tid = GuiCtrlCreateInput("00:00:00", 40, 7, 50, 20) $Button_1 = GUICtrlCreateButton("Launch Notepad @ Set Time", 100, 5, 150) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 If GUICtrlRead($tid, 0) = _NowTime(5) Then ;If $tid <= _NowTime(5) Then Run ("Notepad") EndIf EndSelect WEnd EndFunc ;==>Example Link to comment Share on other sites More sharing options...
Developers Jos Posted July 27, 2013 Developers Share Posted July 27, 2013 You do realize this only works when you click exactly at the correct time ...right? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 27, 2013 Moderators Share Posted July 27, 2013 Scinner, You are only checking the time when you press the button - so unless you press it at exactly the time specified, the condition is not met and you will not start Notepad. And you are not actually checking the time - only the ControlID of the input. I suggest that you do something like this: #include <GUIConstantsEx.au3> #include <Date.au3> Example() Func Example() Local $Button_1, $msg, $fWaiting = False, $sTime GUICreate("Timed Notepad Launcher", 300, 40) GUICtrlCreateLabel("Time:", 10, 10) $tid = GUICtrlCreateInput("00:00:00", 40, 7, 50, 20) $Button_1 = GUICtrlCreateButton("Launch Notepad @ Set Time", 100, 5, 150) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button_1 $sTime = GUICtrlRead($tid) $fWaiting = True GUICtrlSetData($Button_1, "Launch Notepad @" & $sTime) EndSwitch If $fWaiting Then If $sTime = _NowTime(5) Then Run ("Notepad") $fWaiting = False EndIf EndIf WEnd EndFunc ;==>Example That is actually checkiing every few miiliseconds, which is a bit OTT. You could refine it to look at different intervals depending on how close to the required time you get - but you can work on that. M23 Scinner 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Scinner Posted July 27, 2013 Author Share Posted July 27, 2013 You do realize this only works when you click exactly at the correct time ...right? If I try with more than/less than it still doesen't work. #include <GUIConstantsEx.au3> #include <Date.au3> Example() Func Example() Local $Button_1, $msg, $tid, $menutext, $GUI_EVENT_CLOSE GUICreate("Timed Notepad Launcher", 300, 40) Opt("GUICoordMode", 1) GuiCtrlCreateLabel("Time:", 10, 10) $tid = GuiCtrlCreateInput("00:00:00", 40, 7, 50, 20) $Button_1 = GUICtrlCreateButton("Launch Notepad @ Set Time", 100, 5, 150) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 If GUICtrlRead($tid, 0) <= _NowTime(5) Then Run ("Notepad") EndIf EndSelect WEnd EndFunc ;==>Example Please help me! Link to comment Share on other sites More sharing options...
Developers Jos Posted July 27, 2013 Developers Share Posted July 27, 2013 (edited) Why do you assume that comparing numerically works with Time Strings? You need to use _DateDiff() for that. Edited July 27, 2013 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Scinner Posted July 27, 2013 Author Share Posted July 27, 2013 Scinner, You are only checking the time when you press the button - so unless you press it at exactly the time specified, the condition is not met and you will not start Notepad. And you are not actually checking the time - only the ControlID of the input. I suggest that you do something like this: #include <GUIConstantsEx.au3> #include <Date.au3> Example() Func Example() Local $Button_1, $msg, $fWaiting = False, $sTime GUICreate("Timed Notepad Launcher", 300, 40) GUICtrlCreateLabel("Time:", 10, 10) $tid = GUICtrlCreateInput("00:00:00", 40, 7, 50, 20) $Button_1 = GUICtrlCreateButton("Launch Notepad @ Set Time", 100, 5, 150) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button_1 $sTime = GUICtrlRead($tid) $fWaiting = True GUICtrlSetData($Button_1, "Launch Notepad @" & $sTime) EndSwitch If $fWaiting Then If $sTime = _NowTime(5) Then Run ("Notepad") $fWaiting = False EndIf EndIf WEnd EndFunc ;==>Example That is actually checkiing every few miiliseconds, which is a bit OTT. You could refine it to look at different intervals depending on how close to the required time you get - but you can work on that. M23 Thx mate! That was what I was looking for!! Link to comment Share on other sites More sharing options...
Scinner Posted August 1, 2013 Author Share Posted August 1, 2013 I have one more question. I got the Current system time to show in my gui. How can I make this update every 1000ms? #include <GUIConstantsEx.au3> #include <Date.au3> Example() Func Example() Local $Button_1, $current, $fWaiting = False, $sTime GUICreate("Timed Notepad", 450, 90) GUICtrlCreateLabel("Time:", 10, 40) $current = GuiCtrlCreatelabel("Current Time : " & _NowTime(), 10, 10, 200, 20) ; <----- I want this to update every 1000ms as a regular clock $tid = GUICtrlCreateInput("00:00:00", 50, 37, 50, 20) $Button_1 = GUICtrlCreateButton("Open Notepad @ Time", 120, 34, 150) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button_1 $sTime = GUICtrlRead($tid) $fWaiting = True GUICtrlSetData($Button_1, "Open Notepad @" & $sTime) EndSwitch If $fWaiting Then If $sTime = _NowTime(5) Then Run ("Notepad.exe") $fWaiting = False EndIf EndIf WEnd EndFunc ;==>Example Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 1, 2013 Moderators Share Posted August 1, 2013 (edited) Scinner,Either use an Adlib function with a 1000ms interval or use TimerInit/TimerDiff in the loop to check for the 1000ms delay since the last update. Give it a go yourself and come back if you run into problems. M23 Edited August 1, 2013 by Melba23 Typo Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Scinner Posted August 1, 2013 Author Share Posted August 1, 2013 Scinner, Either use an Adlib function with a 1000ms interval or use TimerInit/TimerDiff in the loop to check for the 1000ms delay since the last update. Give it a go yourself and come back if you run into problems. M23 I think I got it! Only thing is the "Current Time" shows up 2 seconds after gui launch. Its really not a problem but can you tell me why it takes 2 seconds for the Curr Time to show up? #include <GUIConstantsEx.au3> #include <Date.au3> AdlibRegister("MyAdlib",1000) Func MyAdlib() $current = GuiCtrlCreatelabel("Current Time : " & _NowTime(), 10, 10, 200, 20) EndFunc ;==>MyAdlib Example() Func Example() Local $Button_1, $current, $fWaiting = False, $sTime GUICreate("Timed Notepad", 450, 90) GUICtrlCreateLabel("Time:", 10, 40) $tid = GUICtrlCreateInput("00:00:00", 50, 37, 50, 20) $Button_1 = GUICtrlCreateButton("Open Notepad @ Time", 120, 34, 150) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button_1 $sTime = GUICtrlRead($tid) $fWaiting = True GUICtrlSetData($Button_1, "Open Notepad @" & $sTime) EndSwitch If $fWaiting Then If $sTime = _NowTime(5) Then Run ("Notepad.exe") $fWaiting = False EndIf EndIf WEnd EndFunc ;==>Example Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 1, 2013 Moderators Share Posted August 1, 2013 Scinner,There is a pause because the first Adlib call is only made after the set interval - just call the function yourself the first time. And if you create the label just the once you can update it in the Adlib like this:expandcollapse popup#include <GUIConstantsEx.au3> #include <Date.au3> Global $cLabel ; The label ControlID needs to be Global <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< AdlibRegister("MyAdlib", 1000) Example() Func Example() Local $Button_1, $current, $fWaiting = False, $sTime GUICreate("Timed Notepad", 450, 90) $cLabel = GUICtrlCreateLabel("", 10, 10, 200, 20) ; Create the label here <<<<<<<<<<<<< MyAdlib() ; Call the function here to set the initial time <<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlCreateLabel("Time:", 10, 40) $tid = GUICtrlCreateInput("00:00:00", 50, 37, 50, 20) $Button_1 = GUICtrlCreateButton("Open Notepad @ Time", 120, 34, 150) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button_1 $sTime = GUICtrlRead($tid) $fWaiting = True GUICtrlSetData($Button_1, "Open Notepad @" & $sTime) EndSwitch If $fWaiting Then If $sTime = _NowTime(5) Then Run("Notepad.exe") $fWaiting = False EndIf EndIf WEnd EndFunc ;==>Example Func MyAdlib() GUICtrlSetData($cLabel, "Current Time : " & _NowTime()) ; And update it here <<<<<<<<<<< EndFunc ;==>MyAdlibAll clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Scinner Posted August 1, 2013 Author Share Posted August 1, 2013 Works like a charm! You da man! Thank you sir! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 1, 2013 Moderators Share Posted August 1, 2013 Scinner,Glad I could help - again! M23 Scinner 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now