amakrkr Posted March 3, 2010 Share Posted March 3, 2010 Hello, i am having problems with this section of code and involves timerinit function call...i dont know what am i doing wrong. expandcollapse popup$timer_1 = _Timer_Init() $timer_2 = _Timer_Init() local $timer11 = 10000,$var1,$var2 local $timer21 = 10000 While 1 Sleep(100) Call("function1") Sleep(100) Call("function2") local $dif1 = _Timer_Diff($timer_1) if $dif1 > $timer11*1000 then if $var1 = 1 Then $timer_1=0 $timer_1 = _Timer_Init() call("function3") EndIf EndIf local $dif2 = _Timer_Diff($timer_2) if $dif2 > $timer21*1000 then if $var2 = 1 Then $timer_2=0 $timer_2 = _Timer_Init() call("function3") EndIf EndIf WEnd Next thing i would like to ask is this (see code example below): ControlSend("Program", "", "", "+3") I was wondering if its possible to send shift key to an inactive window like that? I tied it and it doesnt work somehow and i want to know if its a shift problem so i can start looking for other solutions. Thank you! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 3, 2010 Moderators Share Posted March 3, 2010 amakrkr,Not sure you have quite got the hang of the timers yet! For simple timings like this, just use the built-in Timer commands. Then you need to think about the timimgs im milliseconds - at one point you were waiting for 1000000 msecs, i.e. 16.666666 minutes. Did you really want to wait this long?And why were you using Call for the function calls? Just use the function name. I have trimmed down the code and I hope it shows you how the timers work. You can follow the script by looking in the SciTE console:expandcollapse popupHotKeySet("{ESC}", "On_Exit") Func On_Exit() Exit EndFunc $timer_1 = TimerInit() $timer_2 = TimerInit() Global $timer11 = 10000 ; 10 seconds Global $timer21 = 5000 ; 5 seconds Global $var1 = 1, $var2 =1 While 1 Sleep(1000) function1() Sleep(1000) function2() If TimerDiff($timer_1) > $timer11 Then If $var1 = 1 Then $timer_1 = TimerInit() function3() EndIf EndIf If TimerDiff($timer_2) > $timer21 Then If $var2 = 1 Then $timer_2 = TimerInit() function4() EndIf EndIf WEnd Func function1() ConsoleWrite("Function 1 - " & @SEC & @CRLF) EndFunc Func function2() ConsoleWrite("Function 2 - " & @SEC & @CRLF) EndFunc Func function3() ConsoleWrite("Function 3 - " & @SEC & " - every " & $timer11/ 1000 & " secs" & @CRLF) EndFunc Func function4() ConsoleWrite("Function 4 - " & @SEC & " - every " & $timer21/ 1000 & " secs" & @CRLF) EndFuncYou will see that Functions 3 & 4 sometimes fire a bit over the 5 and 10 seconds set. That is because they must wait until Functions 1 & 2 and the 2 Sleep commands finish. If you want functions to run exactly at the specified time you need to look at AdlibRegister, but we will leave that until another day!I hope that makes it clearer - please ask if you still have questions. 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...
PsaltyDS Posted March 3, 2010 Share Posted March 3, 2010 i am having problems with this section of code and involves timerinit function call...i dont know what am i doing wrong.I don't see the point of it. What was it supposed to do, and what did it do instead? Next thing i would like to ask is this (see code example below): ControlSend("Program", "", "", "+3") I was wondering if its possible to send shift key to an inactive window like that? I tied it and it doesnt work somehow and i want to know if its a shift problem so i can start looking for other solutions.This seems to work fine: Run("notepad.exe", "", @SW_MINIMIZE) WinWait("Untitled - Notepad") $hWin = WinGetHandle("Untitled - Notepad") ControlSend($hWin, "", "Edit1", "+3") Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
amakrkr Posted March 3, 2010 Author Share Posted March 3, 2010 amakrkr, Not sure you have quite got the hang of the timers yet! For simple timings like this, just use the built-in Timer commands. Then you need to think about the timimgs im milliseconds - at one point you were waiting for 1000000 msecs, i.e. 16.666666 minutes. Did you really want to wait this long? And why were you using Call for the function calls? Just use the function name. I have trimmed down the code and I hope it shows you how the timers work. You can follow the script by looking in the SciTE console: expandcollapse popupHotKeySet("{ESC}", "On_Exit") Func On_Exit() Exit EndFunc $timer_1 = TimerInit() $timer_2 = TimerInit() Global $timer11 = 10000 ; 10 seconds Global $timer21 = 5000 ; 5 seconds Global $var1 = 1, $var2 =1 While 1 Sleep(1000) function1() Sleep(1000) function2() If TimerDiff($timer_1) > $timer11 Then If $var1 = 1 Then $timer_1 = TimerInit() function3() EndIf EndIf If TimerDiff($timer_2) > $timer21 Then If $var2 = 1 Then $timer_2 = TimerInit() function4() EndIf EndIf WEnd Func function1() ConsoleWrite("Function 1 - " & @SEC & @CRLF) EndFunc Func function2() ConsoleWrite("Function 2 - " & @SEC & @CRLF) EndFunc Func function3() ConsoleWrite("Function 3 - " & @SEC & " - every " & $timer11/ 1000 & " secs" & @CRLF) EndFunc Func function4() ConsoleWrite("Function 4 - " & @SEC & " - every " & $timer21/ 1000 & " secs" & @CRLF) EndFunc You will see that Functions 3 & 4 sometimes fire a bit over the 5 and 10 seconds set. That is because they must wait until Functions 1 & 2 and the 2 Sleep commands finish. If you want functions to run exactly at the specified time you need to look at AdlibRegister, but we will leave that until another day! I hope that makes it clearer - please ask if you still have questions. M23 that was really helpful ty again Link to comment Share on other sites More sharing options...
amakrkr Posted March 3, 2010 Author Share Posted March 3, 2010 I don't see the point of it. What was it supposed to do, and what did it do instead? This seems to work fine: Run("notepad.exe", "", @SW_MINIMIZE) WinWait("Untitled - Notepad") $hWin = WinGetHandle("Untitled - Notepad") ControlSend($hWin, "", "Edit1", "+3") thx for replay i found out the error was not in my coding but in window that is receiving keys. thx 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