Jump to content
mrtgtr

Do something and again do it after 2 min

Recommended Posts

mrtgtr

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 ?

Share this post


Link to post
Share on other sites
Nine

$ctl = _Timer_SetTimer($handle,2*60*1000,"DoItBabe")

Edited by Nine

Share this post


Link to post
Share on other sites
mrtgtr
1 hour ago, Nine said:

$ctl = _Timer_SetTimer($handle,2*60*1000,"DoItBabe")

how I use it in script

 

 send("{9 down}")

sleep(1500)

 send("{9 up}")

Share this post


Link to post
Share on other sites
Nine

$handle = a window you own, could be your autoit script

"DoitBabe" is a func you will create that do what you want after 2 min.

Search for that UDF it is on autoit help file

Make a script of your own, if it is not working post it and ill help

 

Share this post


Link to post
Share on other sites
mrtgtr

Func Wm()
$ctl=_Timer_SetTimer($hGUI,2*2500,'Wm")

error: syntax error (illegal character)

error: _Timer_SetTimer() : undefined function.


PixelSearch(590 , 742 , 1020 , 742, 0xAA3322)
If @error Then
Send("{9 down}")
Sleep(1700)
Send("{9 up}")
EndIf
EndFunc

Share this post


Link to post
Share on other sites
mrtgtr
1 hour ago, Nine said:

$handle = a window you own, could be your autoit script

"DoitBabe" is a func you will create that do what you want after 2 min.

Search for that UDF it is on autoit help file

Make a script of your own, if it is not working post it and ill help

Func Wm()
$ctl=_Timer_SetTimer($hGUI,2*2500,'Wm")

error: syntax error (illegal character)

error: _Timer_SetTimer() : undefined function.


PixelSearch(590 , 742 , 1020 , 742, 0xAA3322)
If @error Then
Send("{9 down}")
Sleep(1700)
Send("{9 up}")
EndIf
EndFunc

Share this post


Link to post
Share on other sites
Nine

where is $hgui and you cannot call wm within wm. it must be outside wm

and always have opt ("MustDeclareVars",1) at the beginning of your script, it will greatly help you debug

 

Edited by Nine

Share this post


Link to post
Share on other sites
water

Can you please give us some more detailed information about the program you try to automate?
PixelSearch and Send depend on screen size and resolution, window position and might interfere with user actions.
Most of the time there are more reliable ways to do what you want to do.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
iCal (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
mrtgtr
1 hour ago, water said:

Can you please give us some more detailed information about the program you try to automate?
PixelSearch and Send depend on screen size and resolution, window position and might interfere with user actions.
Most of the time there are more reliable ways to do what you want to do.

 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=firefox.ico
#AutoIt3Wrapper_Outfile=firefox.Exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <Misc.au3>

Opt("TrayIconHide", 1)

    ; Create a GUI with various controls.
$hGUI = GUICreate("Google - Mozilla Firefox", 500, 500)
$Start = GUICtrlCreateButton("BAŞLA", 215, 420, 75, 50)
GUICtrlCreateLabel("Durdurmak için + ya bas", 165, 30)
$WMBOX = GUICtrlCreateCheckbox("WM", 75, 50, 100, 60)
GUICtrlSetFont(-1, 16, 800, 0, "Comic Sans MS")
$ZBOX = GUICtrlCreateCheckbox("Z", 75, 100, 100, 60)
GUICtrlSetFont(-1, 16, 800, 0, "Comic Sans MS")
GUICtrlSetTip(-1, "50")
GUISetState(@SW_SHOW)
Local $hDLL = DllOpen("user32.dll")

Global $Timer1 = TimerInit()



While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Start
            runner()
        Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
WEnd




Func Runner()
    While 1

    If _IsPressed("6B", $hDLL) Then
        Exit
    EndIf


    If GUICtrlRead($wmbox) = 1 Then
    WM()
    EndIf

    If GUICtrlRead($ZBOX) = 1 Then
    Z()
    EndIf
    WEnd


    EndFunc


Func kapat()
    Exit
EndFunc



Func WM();when start, this is do it and do every 2 min (loop)
PixelSearch(590 , 742 , 1020 , 742, 0xAA3322)
If @error Then
Send("{9 down}")
Sleep(1700)
Send("{9 up}")
EndIf
EndFunc

Func Z() ;when start, this is do it and do every 1 min (loop)
    Send("{z down}")
    Sleep(100)
    Send("{z up}")
EndFunc

 

Share this post


Link to post
Share on other sites
water

Thanks for the code. But it doesn't explain what you want to achieve with function WM.
Example: You want to wait until a button gets active and then click on this button.
Can you please elaborate?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
iCal (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Nine

First insert at the begining of your script :  Opt ("MustDeclareVars",1)Btw, 2* 2500 is not 2 minutes....

And Wm must have the following arguments :

Func Wm ($hWnd, $iMsg, $iIDTimer, $iTime)

Instead of Global $Timer1 = TimerInit () replace by :

Local $ctl=_Timer_SetTimer($hGUI,2*2500,'Wm")
  if not $ctl then
    MsgBox (0,"test","timer error")
    Exit
  endif 
Edited by Nine

Share this post


Link to post
Share on other sites
Nine
4 minutes ago, Danp2 said:

This looks very suspicious. Why would you be creating an executable named Firefox.exe and the title of "Google - Mozilla Firefox"?

rofl

Share this post


Link to post
Share on other sites
mrtgtr

error: syntax error (illegal character)

error: _Timer_SetTimer(): undefined function.

Share this post


Link to post
Share on other sites
Nine
40 minutes ago, mrtgtr said:

error: syntax error (illegal character)

error: _Timer_SetTimer(): undefined function.

you must have at the beginning of the script :

#include <Timers.au3>

Please look in index of autoit help for _Timer_SetTimer, all the information is in there

Share this post


Link to post
Share on other sites
mrtgtr
1 hour ago, Nine said:

you must have at the beginning of the script :

#include <Timers.au3>

Please look in index of autoit help for _Timer_SetTimer, all the information is in there

 

I did #include <Timers.au3>

now

Local $ctl=_Timer_SetTimer($hGUI,2*2500,'Wm")

error: syntax error (illegal character)

Share this post


Link to post
Share on other sites
BrewManNH
2 minutes ago, mrtgtr said:

Local $ctl=_Timer_SetTimer($hGUI,2*2500,'Wm")

You have a double quote at one end of the Wm, and a single at the other.

  • Haha 1

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
mrtgtr
1 hour ago, BrewManNH said:

You have a double quote at one end of the Wm, and a single at the other.

thanx but now, need to hit 9 but do not do anything after 5 sec autoit gui is crashing

Share this post


Link to post
Share on other sites
Nine

Have you put the parameters to  Func Wm ($hWnd, $iMsg, $iIDTimer, $iTime

If so, bring all your code in so we can see what's going on

Share this post


Link to post
Share on other sites
mrtgtr
2 hours ago, Nine said:

Have you put the parameters to  Func Wm ($hWnd, $iMsg, $iIDTimer, $iTime

If so, bring all your code in so we can see what's going on

While I am searching timers I found this

$Timer = TimerInit()
Func SomeFunction
    $Delay = TimerDiff($Timer)
    $DelayTime = (120000)
    If $Delay > $DelayTime Then
        <your code goes here>
        $Timer = TimerInit()
    EndIf
EndFunc

 

this is good but

it is waiting 2 min and doing it 

I want to do it and wait 2 min and again do it,( again, again, again, loop)

but it is not be sleep it must be timer

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Similar Content

    • Chimp
      By Chimp
      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
    • dersiniar
      By dersiniar
      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  
    • XinYoung
      By XinYoung
      HI! ... this is a big one (at least for me) 
      You guys previously helped me copy the used range in column A and paste them into a Website one at a time in a loop. Cool! Now, for another function, I have 2 columns, A and B, and two input boxes in the Website. I'm having a hard time replicating the loop for the 2 columns. 
      This is how I'm opening the Excel workbook (copied from the previous function that only had 1 column). I need to also get the used range in column B.
      Func OpenExcelForCopy() Global $aBBTableData Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookOpen($oExcel, $ChosenFileName, Default, True, True) $oExcel.Sheets("CopyCourses").Activate ;~ Get all used cells in column A:A Global $aSearchItems = _Excel_RangeRead($oWorkbook, 1, $oWorkbook.Sheets("CopyCourses").Usedrange.Columns("A:A")) ;~ Duplicate the $aSearchItems Array Global $aSearchResult = $aSearchItems ;~ Loop through the array starting at 0 until the end of the array which is (Ubound($aSearchItems) - 1) For $i = 0 To UBound($aSearchItems) - 1 $aSearchResult[$i] = SearchCourseForCopy($aSearchItems[$i]) Next _Excel_RangeWrite($oWorkbook, Default, $aSearchResult, "C1") Finished() EndFunc ;==>OpenExcelForCopy Then we eventually get here. I don't think anything needs to change here but I'm not sure. This is where I paste the data from Column A into an input field (which is a search tool in a website). If the search is good, then we get to the tricky part...
      ;~ OK, we logged in and we searched for a course. Lets COPY it! Func CopyCourseBegin() Local $sResult $iSearchIndex = _ArraySearch($aBBTableData, "Course ID", 0, 0, 0, 1, 1, 0) ;~ If the course was not found, do this. If $iSearchIndex = -1 Then ;~ MsgBox(4096, "Search Error", "Item not found") $sResult = "Source Not Found" _Excel_RangeWrite($oWorkbook, Default, $aSearchResult, "C1") ;~ Now go back to the Excel sheet and search for the next one. ;~ If the course was found, begin the COPY process. Else For $i = 0 To UBound($aSearchItems) - 1 $aSearchResult[$i] = CopyCourseNow($aSearchItems[$i]) Next $sResult = "Copied" _Excel_RangeWrite($oWorkbook, Default, $aSearchResult, "C1") EndIf Return $sResult EndFunc ;==>CopyCourseBegin This is the "tricky part" where I'm confused. I can copy and paste what's in column A just fine, but I can't manage to replicate it for column B. I need to paste whats in Column B into "destinationCourseId"
      ;~ The course search was successful. COPY the course now. Func CopyCourseNow($_sSearchResult) ;~ Navigate to the course copy page. _IENavigate($oIE, $urlBBCourseCopy) ;~ Copy the SOURCE course ID from the Excel sheet ;~ Paste whats copied from column A into the Source Course ID text box Local $oForm = _IEGetObjByName($oIE, "selectCourse") Local $oSearchString = _IEFormElementGetObjByName($oForm, "sourceCourseId") _IEFormElementSetValue($oSearchString, $_sSearchResult) ;~ Paste whats copied from column B into the Destination Course ID text box ?!?!?!?! Local $oForm = _IEGetObjByName($oIE, "selectCourse") Local $oSearchString = _IEFormElementGetObjByName($oForm, "destinationCourseId") _IEFormElementSetValue($oSearchString, $_sSearchResult) ;~ Just exit cause im stuck :( _Exit() EndFunc ;==>CopyCourseNow After I paste the data from column A into "sourceCourseId" and column B into "destinationCourseId", I'll make it do some stuff. Then I need it to loop around until the used ranges in column A & B is finished.
      Does the entire code need to change now that there's two columns?
       
       
    • XinYoung
      By XinYoung
      Why hello there! 
      I have a script reading an Excel sheet (currently only looking at A1), copying the data in that cell, and then searching for it in a Website's search tool. Then it does some stuff if it actually finds something.
      After that, I need it to go back to the Excel sheet, write "yes" into column B if the search was good -- "no" if no results were found, then go down to A2 and do the whole thing all over again until column A has nothing left.
      I really suck at loops and have a hard time grasping how it works. Any help or guidance is really appreciated!
       
      SearchCourse() ;~ Now that were logged in, navigate to the course search page. Func SearchCourse() _IENavigate($oIE, $urlBBCourseSearch) ;~ Change the search criteria to "Course ID" _bbCourseSearchCategoryChange("Course ID") ;~ Open the selected Excel file Local $oAppl = _Excel_Open() Local $oWorkbook = _Excel_BookOpen($oAppl, $ChosenFileName, Default, Default, True) ;~ Copy whats in the first cell (A1) _Excel_RangeCopyPaste($oWorkbook.Worksheets(1), "A1") Global $WhatsCopied = ClipGet() ;~ Paste whats copied into the search text box and click submit Local $oForm = _IEGetObjByName($oIE, "courseManagerFormSearch") Local $oSearchString = _IEFormElementGetObjByName($oForm, "courseInfoSearchText") _IEFormElementSetValue($oSearchString, $WhatsCopied) _IEFormSubmit($oForm) ;~ Lets see what we got from the search Local $oBBTable = _IETableGetCollection($oIE, 2) Global $aBBTableData = _IETableWriteToArray($oBBTable) _ArrayDisplay($aBBTableData) DeleteCourseBegin() EndFunc ;==>SearchCourse ;~ OK, we logged in and we searched for a course. Lets delete it! Func DeleteCourseBegin() $iSearchIndex = _ArraySearch($aBBTableData, "Course ID", 0, 0, 0, 1, 1, 0) ;~ If the course was not found, do this. If $iSearchIndex = -1 Then MsgBox(4096, "Search Error", "Item not found") ;~ Now go back to the Excel sheet and search for the next one....? ;~ If the course was found, begin the deletion process. Else MsgBox(4096, "Search Success", $aBBTableData[$iSearchIndex][0] & " = " & $aBBTableData[$iSearchIndex][1]) DeleteCourseNow() EndIf EndFunc ;==>DeleteCourseBegin ;~ The course search was successful. Delete the course now. Func DeleteCourseNow() ;~ Click the checkbox located beside the course that has been found. Local $CheckBox = _IEGetObjByName($oIE, "ckbox") _IEAction($CheckBox, "click") _IELoadWait($oIE) ;~ Click the Delete button. _IELinkGetCollection($oIE) Local $oLinks = _IELinkGetCollection($oIE) For $oLink In $oLinks If $oLink.href = "javascript:validateRemove();" Then _IEAction($oLink, "click") ExitLoop EndIf Next ;~ Click the "Delete course, including all of its files" radio button. Local $RadioButton = _IEGetObjById($oIE, "removeAllFiles_t") _IEAction($RadioButton, "click") _IELoadWait($oIE) ;~ Click the "Submit" button Local $Submit = _IEGetObjByName($oIE, "bottom_Submit") _IEAction($Submit, "click") _IELoadWait($oIE) ;~ Now go back to the Excel sheet and search for the next one....? EndFunc ;==>DeleteCourseNow  
       
    • omicron
      By omicron
      Hello!

      I am working on a function that I am just getting lost on. The goal is a multiple nested loop.

      Here are the steps:
      Contents of file1.txt::
      [topic] var1=Name var2=OtherName var3=SomeotheName Contents of file2.txt::
      [subTopic] top=sub1 top2=sub2 top3=sub3 The Shell I am working from::
      #include <file.au3> $file = "c:\yourfile.txt" FileOpen($file, 0) For $i = 1 to _FileCountLines($file) $line = FileReadLine($file, $i) msgbox(0,'','the line ' & $i & ' is ' & $line) Next FileClose($file) Understanding however that the "msgbox" needs to then become a variable. in example the following::
      $file = "c:\yourfile.txt" FileOpen($file, 0) While true( prog.exe is running && "WinName" is open) do For $i = 1 to _FileCountLines($file) $line = FileReadLine($file, $i) ;Open File to log "current location of file 1" FileWriteLine ("filename", $i & ' is ' & $line) var = $line Next $file2 = "c:\yourfile.txt" FileOpen($file, 0) For $i = 1 to _FileCountLines($file) $line = FileReadLine($file, $i) ; OpenFile to log "Current location of file 2" FileWriteLine ("filename", $i & ' is ' & $line) Next FileClose($file2) FileClose($file) The goal in written form is the following ::

      While in "OpenWindow"
          read from file 1 starting at line 1 until end of file.
         file 1 is a list of names to be searched.
         With $line selected, add this element to the element in file 2.
       
      The search of a variables in list 1 and list 2 differ on the amount of posts that day. (This is not a web based platform, it is a game) I need to search 2 names and take a screenshot of the out put. The sizes of the names list depend on the activity of names at the time of search.
      This loop continues until all the names from both lists have been searched. Mostly in the format of::
      File1= item
      File2= Vendor
       
      Item + Vendor  ( Capture screen, scroll) -- Not sure how to detect if I need to scroll)
       
      Thank you for your help and support!
×