Jump to content

How would I go about making a timer?


 Share

Recommended Posts

Okay, I'm making a program to Auto-Post on some forums. The time I need to wait between posts is 45 seconds as a minimum. The program I'm making right now uses multiple accounts to post. I need to make a timer that runs in the background, so I can use that as a base to when posts are made, and to know weather I should have the program wait longer to post, or allow it to post by looking at the time difference.

So basically what I'm trying to say is...How would I go about making that timer?

Edited by SteveO
Link to comment
Share on other sites

Okay, I'm making a program to Auto-Post on some forums. The time I need to wait between posts is 45 seconds as a minimum. The program I'm making right now uses multiple accounts to post. I need to make a timer that runs in the background, so I can use that as a base to when posts are made, and to know weather I should have the program wait longer to post, or allow it to post.

So basically what I'm trying to say is...How would I go about making that timer?

Timers are fairly simple to write but without seeing how you want to use the timer and where it should be inserted you should post the pertinent portion of your code.

Method 1

$Time = TimerInit()
Do
   Sleep(100)
Until TimerDiff($Time) >= 45000

Method 2

$Time = 0
While $Time < 45
   Sleep(1000)
   $Time += 1
Wend

Method 3

For $I = 1 To 45
   Sleep (1000)
Next

Method 4

Sleep (45000)

There is also a way to do it using AdLibEnable()

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Timers are fairly simple to write but without seeing how you want to use the timer and where it should be inserted you should post the pertinent portion of your code.

Method 1

$Time = TimerInit()
Do
   Sleep(100)
Until TimerDiff($Time) >= 45000

Method 2

$Time = 0
While $Time < 45
   Sleep(1000)
   $Time += 1
Wend

Method 3

For $I = 1 To 45
   Sleep (1000)
Next

Method 4

Sleep (45000)

There is also a way to do it using AdLibEnable()

Thanks GEO, I'll finish the account switch and posting functions either tonight or tomorrow, and I'll post them on here.
Link to comment
Share on other sites

Thanks GEO, I'll finish the account switch and posting functions either tonight or tomorrow, and I'll post them on here.

All we need to see is what function you want called when the timer hits 45 seconds and the portion of the script where you would want to add the timer.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>

Global Enum $TIMERID1 = 1001, $TIMERID2
Global $iMemo

_Main()

Func _Main()
    Local $hGUI, $iTimer1, $iTimer2
    
    $hGUI = GUICreate("My Timers", 400, 296)
    $iMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, BitOR($WS_HSCROLL, $WS_VSCROLL))
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()
    
    GUIRegisterMsg($WM_TIMER, "WM_TIMER")
    
    $iTimer1 = _WinAPI_SetTimer($hGUI, $TIMERID1, 5000)
    $iTimer2 = _WinAPI_SetTimer($hGUI, $TIMERID2, 3000)
    
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    _WinAPI_KillTimer($hGUI, $iTimer1)
    _WinAPI_KillTimer($hGUI, $iTimer2)
    
EndFunc   ;==>_Main

; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

Func _WinAPI_KillTimer($hWnd, $iIDEvent)
    Local $iResult = DllCall("user32.dll", "int", "KillTimer", "hwnd", $hWnd, "int", $iIDEvent)
    If @error Then Return SetError(-1, -1, 0)
    Return $iResult[0] <> 0
EndFunc   ;==>_WinAPI_KillTimer

Func _WinAPI_SetTimer($hWnd, $iIDEvent, $iElapse, $pTimerFunc = 0)
    Local $iResult = DllCall("user32.dll", "int", "SetTimer", "hwnd", $hWnd, "int", $iIDEvent, "int", $iElapse, "ptr", $pTimerFunc)
    If @error Then Return SetError(-1, -1, 0)
    Return $iResult[0]
EndFunc   ;==>_WinAPI_SetTimer

Func WM_TIMER($hWnd, $iMsg, $iwParam, $ilParam)
    Switch $iwParam
        Case $TIMERID1
            MemoWrite("Timer 1 Fired")
        Case $TIMERID2
            MemoWrite("Timer 2 Fired")
    EndSwitch
EndFunc   ;==>WM_TIMER

Edited by GaryFrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

2nd Example using Callback Function(s)

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>

Global Enum $TIMERID1 = 1001, $TIMERID2
Global $iMemo

_Main()

Func _Main()
    Local $hGUI, $iTimer1, $iTimer2, $hCallBack, $hCallBack2
    
    $hGUI = GUICreate("My Timers", 400, 296)
    $iMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, BitOR($WS_HSCROLL, $WS_VSCROLL))
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()
    
    $hCallBack = DllCallbackRegister("_TimerCallBackFunc", "none", "hwnd;int;int;dword")
    $hCallBack2 = DllCallbackRegister("_TimerCallBackFunc", "none", "hwnd;int;int;dword")
    
    $iTimer1 = _WinAPI_SetTimer($hGUI, $TIMERID1, 5000, DllCallbackGetPtr($hCallBack))
    $iTimer2 = _WinAPI_SetTimer($hGUI, $TIMERID2, 3000, DllCallbackGetPtr($hCallBack2))
    
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    _WinAPI_KillTimer($hGUI, $iTimer1)
    _WinAPI_KillTimer($hGUI, $iTimer2)
    DllCallbackFree($hCallBack)
    DllCallbackFree($hCallBack2)
EndFunc   ;==>_Main

; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

Func _WinAPI_KillTimer($hWnd, $iIDEvent)
    Local $iResult = DllCall("user32.dll", "int", "KillTimer", "hwnd", $hWnd, "int", $iIDEvent)
    If @error Then Return SetError(-1, -1, 0)
    Return $iResult[0] <> 0
EndFunc   ;==>_WinAPI_KillTimer

Func _WinAPI_SetTimer($hWnd, $iIDEvent, $iElapse, $pTimerFunc = 0)
    Local $iResult = DllCall("user32.dll", "int", "SetTimer", "hwnd", $hWnd, "int", $iIDEvent, "int", $iElapse, "ptr", $pTimerFunc)
    If @error Then Return SetError(-1, -1, 0)
    Return $iResult[0]
EndFunc   ;==>_WinAPI_SetTimer

Func _TimerCallBackFunc($hWnd, $Msg, $iIDTimer, $dwTime)
    MemoWrite("Timer " & $iIDTimer & " Fired")
EndFunc   ;==>_TimerCallBackFunc

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Gary that makes my 4 lines pale by comparison. Nice work.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Gary that makes my 4 lines pale by comparison. Nice work.

Suprised myself, got it working the 1st time.

Made a topic of those 2 examples in Examples Scripts.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Suprised myself, got it working the 1st time.

Made a topic of those 2 examples in Examples Scripts.

Good. maybe someone ( read you) should make a whole timer.au3 UDF.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Okay, I finished my Posting Function.

Where I have the "Sleep(Random($min, $max, 1))" I need the wait time customized for each account used. Since there's a 45 second minimum cooldown between posts, and that cooldown is account based, I need each wait time specified for each account used.

So what I was thinking was to put down the time that the post was made in an array. Then I have it look at the array the second time around, and see if AT LEAST 45 seconds have passed, and if AT LEAST 45 seconds haven't passed, i'll have it logout and try another account at random, and do the check again, and switch accounts again, until it finds one that has at least 45 seconds passed.

So Basically this was the process I was planning but I have no idea how to implement it.

- Start Clock

- Login

- Post

- Record time of post in an array for that specific account

- Logout

- Login

- Compare time of last post of that account to current Clock time and see if at least 45 seconds have past. (IF not, then wait)

- Post

- Record time of post in an array for that specific account

- Logout

Func NumPost()
    For $I = $startpost To $endpost
        _IENavigate($IE,$Thread[2] & $sid)
        $Post = _IEFormGetObjByName($IE,"post")
        $Mess = _IEFormElementGetObjByName($Post,"message")
        _IEFormElementSetValue($Mess, $startglobalbbcode & $Message & $endmsgbbcode & $startnumbbbcode & $sym & $I & $endglobalbbcode)
        _IEFormImageClick ($Post,"Submit","alt")
        $I = $I+1
        
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;        
            ;; Early Post End Check
            If $I == $endpost + 1 Then  
                If $tymsgonoff == 1 Then
                            Sleep(Random($min, $max, 1))
                            _IENavigate($IE,$Thread[3] & $sid)
                            $Post = _IEFormGetObjByName($IE,"post")
                            $Mess = _IEFormElementGetObjByName($Post,"message")
                            _IEFormElementSetValue($Mess, $tymsg)
                            _IEFormImageClick ($Post,"Submit","alt")
                            ;;End Msg
                            MsgBox(0, "The Bumping Catalyst v" & $ver, "Bumping Completed")
                            Exit
                Else
            MsgBox(0, "The Bumping Catalyst v" & $ver, "Bumping Completed")
            Exit
            EndIf
            EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    
        Logout()
        Login()
        Sleep(Random($min, $max, 1))
                        _IENavigate($IE,$Thread[3] & $sid)
        $Post = _IEFormGetObjByName($IE,"post")
        $Mess = _IEFormElementGetObjByName($Post,"message")
        _IEFormElementSetValue($Mess, $startglobalbbcode & $Message & $endmsgbbcode & $startnumbbbcode & $sym & $I & $endglobalbbcode)
        _IEFormImageClick ($Post,"Submit","alt")
        Sleep(Random($min, $max, 1))
        Logout()
        Login()
    Next
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;        
                If $tymsgonoff == 1 Then
                            Sleep(Random($min, $max, 1))
                            _IENavigate($IE,$Thread[2] & $sid)
                            $Post = _IEFormGetObjByName($IE,"post")
                            $Mess = _IEFormElementGetObjByName($Post,"message")
                            _IEFormElementSetValue($Mess, $tymsg)
                            _IEFormImageClick ($Post,"Submit","alt")
                            ;;End Msg
                            MsgBox(0, "The Bumping Catalyst v" & $ver, "Bumping Completed")
                            Exit
                Else
                MsgBox(0, "The Bumping Catalyst v" & $ver, "Bumping Completed")
                Exit
                EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    EndFunc
Link to comment
Share on other sites

Okay, I finished my Posting Function.

Where I have the "Sleep(Random($min, $max, 1))" I need the wait time customized for each account used. Since there's a 45 second minimum cooldown between posts, and that cooldown is account based, I need each wait time specified for each account used.

So what I was thinking was to put down the time that the post was made in an array. Then I have it look at the array the second time around, and see if AT LEAST 45 seconds have passed, and if AT LEAST 45 seconds haven't passed, i'll have it logout and try another account at random, and do the check again, and switch accounts again, until it finds one that has at least 45 seconds passed.

So Basically this was the process I was planning but I have no idea how to implement it.

- Start Clock

- Login

- Post

- Record time of post in an array for that specific account

- Logout

- Login

- Compare time of last post of that account to current Clock time and see if at least 45 seconds have past. (IF not, then wait)

- Post

- Record time of post in an array for that specific account

- Logout

Hi Steve. Sorry it took so long to get back to you.

Try This

Note: This sets a delay of 45 seconds + your rabdom time so You may have to play with your $min & $max values

Func NumPost()
   For $I = $startpost To $endpost
        _IENavigate($IE,$Thread[2] & $sid)
        $Post = _IEFormGetObjByName($IE,"post")
        $Mess = _IEFormElementGetObjByName($Post,"message")
        _IEFormElementSetValue($Mess, $startglobalbbcode & $Message & $endmsgbbcode & $startnumbbbcode & $sym & $I & $endglobalbbcode)
        _IEFormImageClick ($Post,"Submit","alt")
      $I = $I+1
      
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;      
         ;; Early Post End Check
         If $I == $endpost + 1 Then   
            If $tymsgonoff == 1 Then
                     Sleep(Random($min, $max, 1))
                     _IENavigate($IE,$Thread[3] & $sid)
                     $Post = _IEFormGetObjByName($IE,"post")
                     $Mess = _IEFormElementGetObjByName($Post,"message")
                     _IEFormElementSetValue($Mess, $tymsg)
                     _IEFormImageClick ($Post,"Submit","alt")
                     ;;End Msg
                     MsgBox(0, "The Bumping Catalyst v" & $ver, "Bumping Completed")
                     Exit
            Else
         MsgBox(0, "The Bumping Catalyst v" & $ver, "Bumping Completed")
         Exit
         EndIf
         EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   
      Logout()
      Login()
      $Time = TimerInit()
      Do
         Sleep(100)
      Until TimerDiff($Time) >= 45000
      Sleep(Random($min, $max, 1))
                      _IENavigate($IE,$Thread[3] & $sid)
        $Post = _IEFormGetObjByName($IE,"post")
        $Mess = _IEFormElementGetObjByName($Post,"message")
        _IEFormElementSetValue($Mess, $startglobalbbcode & $Message & $endmsgbbcode & $startnumbbbcode & $sym & $I & $endglobalbbcode)
        _IEFormImageClick ($Post,"Submit","alt")
        Sleep(Random($min, $max, 1))
      Logout()
      Login()
    Next
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;      
            If $tymsgonoff == 1 Then
                     $Time = TimerInit()
                     Do
                        Sleep(100)
                     Until TimerDiff($Time) >= 45000
                     Sleep(Random($min, $max, 1))
                     _IENavigate($IE,$Thread[2] & $sid)
                     $Post = _IEFormGetObjByName($IE,"post")
                     $Mess = _IEFormElementGetObjByName($Post,"message")
                     _IEFormElementSetValue($Mess, $tymsg)
                     _IEFormImageClick ($Post,"Submit","alt")
                     ;;End Msg
                     MsgBox(0, "The Bumping Catalyst v" & $ver, "Bumping Completed")
                     Exit
            Else
            MsgBox(0, "The Bumping Catalyst v" & $ver, "Bumping Completed")
            Exit
            EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   EndFunc

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...