Jump to content

Random random's?


Recommended Posts

I have 3 random declarations, and i am wondering, is there a way to randomize the Send() function?

Like if i have $letter1, $letter2, and $letter3, how can i make it so it sends one of those, at random?

Also: I have this script, and it only seems to run once, then it just spams text forever instead of completing the whole sequence, im not sure why.

;MOUSE X Y ---- 682 , 420
;START BUTTON - 507 , 504
sleep(1000)
HotKeySet("z","qt")
Func qt()
    Exit
EndFunc

Global $Letter, $num, $Letter2, $Letter3
While 1
    MouseClick("left",682,420)
    sleep(50)
    Send("{Backspace 10}")
    sleep(50)
Do
    $Letter = Chr(Random(Asc("A"), Asc("Z"), 1))
;$Letter2 = Chr(Random(Asc("a"), Asc("z"), 1))
;$Letter3 = Int(Random(0,9))
    send($letter)
    $num = $num + 1
Until $num = Int(random(7,9))
    MouseClick("left",507,504)
    WinWaitActive("Warning")
    Sleep(50)
    send("{Enter}")
    sleep(1500)
Wend
Edited by Juggernaut
Link to comment
Share on other sites

Actually! I didnt fix it :{

After a few times it does it perfect, and then it goes back to just sending random text nonstop. or the program just closes..

This is what I have now.

;MOUSE X Y ---- 682 , 420
;START BUTTON - 507 , 504
sleep(1000)
HotKeySet("z","qt")
Func qt()
    Exit
EndFunc

Global $Letter, $num, $Letter2, $Letter3
While 1
    MouseClick("left",682,420)
    sleep(50)
    Send("{Backspace 10}")
    sleep(50)
Do
    Dim $letter[3]
    $letter[0] = Chr(Random(Asc("A"), Asc("Z"), 1))
    $letter[1] = Chr(Random(Asc("a"), Asc("z"), 1))
    $letter[2] = Int(Random(0,9, 1))
    Send($letter[Random(0, UBound($letter) - 1, 1)])
    $num = $num + 1
Until $num = Int(random(7,9))
    $num = 0
    MouseClick("left",507,504)
    WinWaitActive("Warning")
    Sleep(50)
    send("{Enter}")
    sleep(1500)
Wend
Edited by Juggernaut
Link to comment
Share on other sites

You should fix that Do-Until loop, using Random() as the ending condition can cause an infinite loop. Use a For-loop instead.

For $x = 1 to Random(7, 9, 1)
    MsgBox(0, "Count down!", $i)
Next

Also it's unnecessary to have Int() infront of every Random() since the third parameter in Random() gives integers when you set it to 1.

The Asc() is unnecessary too, it would be faster do directly use their numbers, see "ASCII Characters" in the helpfile or if you are lazy run:

MsgBox(0, "", Asc("A") & ":" & Asc("Z") & ":" & Asc("a") & ":" & Asc("z"))
Link to comment
Share on other sites

Can anyone figure out why it just randomly stops and wont stop sending keys?

... because that is what you programed it to do :-)

You script sends the letter "z" at random times.

You coded the letter "z" to quit the script. :-)

try HotKeySet("{ESC}","qt")

This line of code is why the script "won't stop sending keys" at times.

Until $num = Int(Random(7, 9))

Each time thru your Do/Until loop, you increment $num by one...

...so, lets see how that gets evaluated when it hits the "Until" line.

$num = 4 and Int(Random(7, 9)) = 8

$num = 5 and Int(Random(7, 9)) = 7

$num = 6 and Int(Random(7, 9)) = 7

$num = 7 and Int(Random(7, 9)) = 8

$num = 8 and Int(Random(7, 9)) = 7

$num = 9 and Int(Random(7, 9)) = 8

$num = 10 and Int(Random(7, 9)) = 7

...continues until you kill the script or until AutoIt reaches its limits.

You might want to change this line from

Until $num = Int(Random(7, 9))

to

Until $num > Random(7, 9, 1)

Also this line from

$letter[2] = Int(Random(0,9, 1))

to

$letter[2] = Random(0,9, 1)

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...