IamKJ

Executing functions at specific times

8 posts in this topic

#1 ·  Posted (edited)

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.

Edited by IamKJ

Share this post


Link to post
Share on other sites



#2 ·  Posted

Have you looked at TimerInit and TimerDiff functions?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Yes, but those only act from when it was called.  I want to go off of system time.  For example, this script would ask them to input time to execute, so I'd put "03:30:00:000", and I'd like for it to execute at 3:30 A.M.  

 

I can get the system time displayed fine and everything, but can't figure out how to get autoit to read the time as a string and execute when that system time string reaches to time specified.

 

It might be possible/easier for it to read the time as a whole number, maybe if you add all the times (hh + mm + ss + ms) and get a whole number, that might work, but not sure how to get autoit to read the system time as a string or integer.

Edited by IamKJ

Share this post


Link to post
Share on other sites

#4 ·  Posted

Sorry misread your post, what about:

#include <Date.au3>
Global $infotime
Global $iTicks
timer()
Func timer ()
    If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
    $iMsgBoxAnswer = MsgBox(36,"Timer","Please format your answer in 00:00:00")
    Select
        Case $iMsgBoxAnswer = 6 ;Yes
            $infotime = InputBox ('Time', 'What time to execute?')
            $iTicks = _TimeToTicks(StringLeft($infotime, 2), StringMid($infotime, 4, 2), StringRight($infotime, 2))
            Do
                ToolTip(@Hour & ':' & @Min & ':' & @Sec)
            Until _TimeToTicks(@HOUR, @MIN, @SEC) = $iTicks
            MsgBox(0,'Worked','Worked')
        Case $iMsgBoxAnswer = 7 ;No
            Exit
    EndSelect
EndFunc

 

1 person likes this

Share this post


Link to post
Share on other sites

#5 ·  Posted

That worked perfectly.  However, it won't allow me to use the _Msec function in  _TimeToTicks, which returns milliseconds.

Share this post


Link to post
Share on other sites

#6 ·  Posted

It worked with the msgbox, but anything else I try to put after the Until statement just makes the original message box pop up.

Share this post


Link to post
Share on other sites

#7 ·  Posted

Can you give an example, I replaced the MsgBox with RunWait("Notepad.exe") and it worked fine.

Also regards your OP if you used the following it should also work, the issue previously is that you were reading ToolTip which just returned 0.

#include <Array.au3>
#include <Date.au3>
Global $infotime
timer()
Func timer ()
    $sTime = _DateAdd("s", 30, _NowCalc())
    $aTime = StringSplit($sTime, " ")
    $infotime = InputBox ('Time', 'What time to execute?', $aTime[2] & ":000")
    Do
        $sRawTimer = @Hour & ':' & @Min & ':' & @Sec & ':' & _MSec()
        ToolTip($sRawTimer)
    Until $sRawTimer = $infotime
    If $sRawTimer = $infotime Then MsgBox(0,'Worked','Worked')
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

1 person likes this

Share this post


Link to post
Share on other sites

#8 ·  Posted

The second code you posted worked beautifully every time.   It doesn't work all the time with the milliseconds, but that's fine, have found a way around that with using the sleep time and converting milliseconds into sleep time.  Thanks a lot!

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

    • P3rsp3ctiv3
      By P3rsp3ctiv3
      Hello how can I send a {Enter} into the edit window ($cmd)? I tried it first with:
      GUICtrlSetData($cmd, "Line 1" + "{ENTER}")
      but it doesn´t work. Can someone help me please?
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> $Admin = GUICreate("Admin", 234, 168, 192, 229, $GUI_SS_DEFAULT_GUI, BitOR($WS_EX_OVERLAPPEDWINDOW,$WS_EX_TRANSPARENT,$WS_EX_WINDOWEDGE)) GUISetBkColor(0xB4B4B4) $exit = GUICtrlCreateButton("Close", 160, 136, 65, 25) $cmd = GUICtrlCreateEdit("",0, 0, 225, 137, $ES_AUTOVSCROLL + $WS_VSCROLL) GUICtrlSetData(-1, "") GUICtrlSetFont(-1, 10, 400, 0, "Candara") GUICtrlSetBkColor(-1, 0xE3E3E3) $cmd_clear = GUICtrlCreateButton("Clear", 9, 136, 65, 25) GUISetState(@SW_SHOW) HotKeySet("{f1}", CMD_1) HotKeySet("{f2}", CMD_2) While 1 $msg = GUIGetMsg(1) Switch $msg[0] Case $GUI_EVENT_CLOSE Exit Case $exit GUIDelete($Admin) Exit EndSwitch WEnd Func CMD_1(); GUICtrlSetData($cmd, "Line 1" & "{ENTER}") GUICtrlSetData($cmd, "Line 2" & "{ENTER}") EndFunc Func CMD_2(); GUICtrlSetData($cmd, "Line 3" & "{ENTER}") GUICtrlSetData($cmd, "Line 4" & "{ENTER}") EndFunc
    • nacerbaaziz
      By nacerbaaziz
      hello
      please i need to link a progress bar with a time can you help me?
      e.g
      i want to set a progress bar for 10 sec
      am waiting for your answers
      thank you.
    • AdminC
      By AdminC
      #RequireAdmin
      #include <SendMessage.au3>
      #include <WinAPI.au3>
      #include <WindowsConstants.au3>
      #include <GDIPlus.au3>
      #include <GUIConstantsEx.au3>
      #include <WinAPIGdi.au3>
      #include <Array.au3>
      #include <WinAPIDiag.au3>
      $Imglocation = @ScriptDir&"\Image\testimg.bmp"
      _GDIPlus_Startup()
      Local $Bitmap = _GDIPlus_BitmapCreateFromFile($Imglocation)
      Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Bitmap)
      Local $imgSize = _WinAPI_GetBitmapDimension($hBitmap)
      Local $imgBits = DllStructCreate('dword[' & ($imgSize.X * $imgSize.Y) & ']')
      _WinAPI_GetBitmapBits($hBitmap, DllStructGetSize($imgBits), DllStructGetPtr($imgBits))
      _WinAPI_DisplayStruct($imgBits)
      MsgBox(0, "", DllStructGetData($imgBits, 1, 1)) 
      _GDIPlus_Shutdown()
      DllstructGetData can't get data color B, G, R value. Who's know that? teach me plz
       
    • Miliardsto
      By Miliardsto
      Hello. Im trying to make my scripts safe - unnable to decompile. I search for obfuscators and other security methods but the search has come to nothing.
      Then one guy gave that idea below. If I rightly understood this idea lets we talk about example program with this secutiy method.
      Program have two parts, first is only login gui and the second part is the main program Second part (main program) is uploaded on ftp server lets say that on http://xxx/autoit/main_program.au3 So we have the first gui with login, we put correctly login and pass and this is the moment when code from http://xxx/autoit/main_program.au3 will be downloaded and executed Finally main program will be appear This is the similiar way like new games are protected by cracking.
      I have few questions in this moment about this:
      Is something like that even possible to do with the autoit? First part of program (login gui) must have somewhere given that link to download the rest of code - http://xxx/autoit/main_program.au3 to make it execute. As we know this first part of program is easy able to hack and retrieve this web url http://xxx/autoit/main_program.au3 where located is main part of program. Is the way to encrypt or secure it? If only code will be stored in .php we know it cannot be previewed. So it could for example get code from .php file instead of .au3 I know that methods works in other languages (I dont know exactly how) thats becouse I only speculates, maybe something may looks different in these solution? Other way would be compiling second part of code on web server (there are available web autoit servers) maybe this way is possible? Tell me anything U know about this ideas and if its even possible to achieve.
      Thanks for ur any response, advice or thoughts
       

       
       
    • dubd83
      By dubd83
      I am trying to click on a tab within an SWT_Window0. The problem is autoit can not see the tab's text and there is no controlid. I have tried using commands to obtain a handle and text with no luck. Any ideas on how to get control of this tab?