frustatedprogrammer Posted November 20, 2014 Posted November 20, 2014 Hello Good day I'm recently studying Autoit by exploring other's script, this is my question is there something i can use beside the term (sleep) ex: (sleep 50) because it completely stopping anyother script thats going on. ill be using it by pressing f5 and f6 every 5 minutes without using the sleep because as i said sleep is stopping any ongoing script that i;am using , thanks
Malkey Posted November 20, 2014 Posted November 20, 2014 Maybe the AdlibRegister function will interest you. This is a modified example of the example in the help file found under the AdlibRegister function. AdlibRegister("MyAdLibFunc", 2000) ; Run MyAdLibFunc() every 2 secs. ; Sleep does not stop AdLib functions from running. Sleep(10000) ; Sleep for 10 secs ; Unregister the function MyAdLibFunc() from being called every 2000ms. AdlibUnRegister("MyAdLibFunc") Func MyAdLibFunc() ; Assign a static variable to hold the number of times the function is called. Local Static $iCount = 0 $iCount += 1 MsgBox(1, "", "MyAdLibFunc called " & $iCount & " time(s)", 1) ; Show for 1 sec EndFunc ;==>MyAdLibFunc And being your first post - welcome.
frustatedprogrammer Posted November 20, 2014 Author Posted November 20, 2014 wow, thanks for the effort really appreciate it. tyvm
frustatedprogrammer Posted November 20, 2014 Author Posted November 20, 2014 i cant get this thing to work.... i just need some simple codes that press X key every 5 mins without using sleep thanks if u can answer this, really appreciate ur help
Solution alienclone Posted November 20, 2014 Solution Posted November 20, 2014 (edited) I have not tested this, but in theory it should do the trick. EDIT: it is tasking on the cpu when a sleep is not added. this script was using 27% of my cpu while running, because it is checking the time like every millisecond or something like that. adding a small sleep(900) inside the do..until reduced that to 0% EDIT2: after testing my script, it does not do as i expected. it adds 5 to the hour, not the minutes. sorry edited the script below to work correctly. i hope #include <Date.au3> while 1 $start=_NowCalc() $five = _DateAdd('n', 5, _NowCalc()) Do sleep(900) $now=_NowCalc() Until $now=$five ;press x key command here WEnd Edited November 20, 2014 by alienclone If @error Then MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!") EndIf "Yeah yeah yeah patience, how long will that take?" -Ed Gruberman REAL search results | SciTE4AutoIt3 Editor Full Version
Malkey Posted November 20, 2014 Posted November 20, 2014 This example is based on alienclone's example. For testing, seconds are used, For minutes replace both @SEC each with the @MIN macro. #include <Misc.au3> While Not _IsPressed("1B") ; xPress Esc key to exit $start = @SEC ; @MIN ; ;ConsoleWrite($start & @LF) $five = Mod($start + 5, 60) ;ConsoleWrite($five & @LF) Do $now = @SEC ; @MIN ; Sleep(10) ; Sleep in a loop lowers CPU usage. Until $now = $five Or _IsPressed("1B") Send("x") ; press x key command here WEnd
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