Sign in to follow this  
Followers 0
frustatedprogrammer

other script i can besides (sleep)

6 posts in this topic

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

Share this post


Link to post
Share on other sites



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.  :bye:

Share this post


Link to post
Share on other sites

wow, thanks for the effort really appreciate it.

tyvm

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I have not tested this, but in theory it should do the trick.

:alien:

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  :sweating:

edited the script below to work correctly. i hope  :thumbsup:

#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 by alienclone

if @error Then
	MsgBox(262192,"",@ComputerName&" slaps "&@UserName&" around a bit with a large trout!")
	EndIf

>Exit code: 0

REAL search results

"Yeah yeah yeah, patience. How long will that take?"  -Ed Gruberman

Share this post


Link to post
Share on other sites

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

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
Sign in to follow this  
Followers 0