Jump to content

other script i can besides (sleep)

Go to solution Solved by alienclone,

Recommended Posts

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

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.

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:

Link to post
Share on other sites
  • Solution

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

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

#include <Date.au3>

while 1
$five = _DateAdd('n', 5, _NowCalc())
Until $now=$five
;press x key command here


Edited by alienclone
If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")

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

REAL search results

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)
        $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
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...