Sign in to follow this  
Followers 0
Guest Demvaril

Random

6 posts in this topic

#1 ·  Posted (edited)

Hi , I need a macro that will hit the same key between 2 set times.

For example hit the "x" key at a random time between 45 and 50 secs. At the moment I have a macro that hits the same key at a preset time, like 45000 for 45 seconds. I am not at work at the moment so cannot show the macro i have, but it was a pretty simple one.

Thanks for any help.

been to work and this is the script i am using :ph34r:

$i = 0

Do

Sleep(52000)

Send("s")

Until $i = 1

Would adding

Sleep(Random(2000, 5000))

at the end of the script work? or should i replace "Sleep(52000)" with "Sleep(Random(52000, 55000))

Any help appreciated.

Edited by Demvaril

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Dim $mint, $maxt
$mint = 45  ;Set the min time in seconds. 
$maxt = 50  ;Set the max time in seconds.

If $maxt < $mint Then Exit

While 1
    Sleep($mint * 1000)
    Sleep(Int(Random($maxt - $mint + 1)) * 1000) ;*
    Send('s')
Wend

;* The point to this line is calculate the max time the script should sleep.
;adding 1 to it (since Random() do not include max in its results) truncate
;decimal part of the Random result and sleep that number of seconds.

Edited by ezzetabi

Share this post


Link to post
Share on other sites

Dim $mint, $maxt
$mint = 45  ;Set the min time in seconds. 
$maxt = 50  ;Set the max time in seconds.

If $maxt < $mint Then Exit

While 1
    Sleep($mint * 1000)
    Sleep(Int(Random($maxt - $mint + 1)) * 1000);*
    Send('s')
Wend

;* The point to this line is calculate the max time the script should sleep.
;adding 1 to it (since Random() do not include max in its results) truncate
;decimal part of the Random result and sleep that number of seconds.

<{POST_SNAPBACK}>

Think it can also be done with one sleep command:

Sleep(Random($mint,$maxt) * 1000)

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Of course, but it seemed more clear for a noob to me.

Btw your code never arrive waiting to $maxt seconds :ph34r:

It should be:

Sleep(Int(Random($mint,$maxt + 1)) * 1000)

:(

Share this post


Link to post
Share on other sites

Of course, but it seemed more clear for a noob to me.

Btw your code never arrive waiting to $maxt seconds  :(

It should be:

Sleep(Int(Random($mint,$maxt + 1)) * 1000)

:lol:

<{POST_SNAPBACK}>

You are rigth... I am of 1/1000s of a second :ph34r:

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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