Jump to content

Randomize send "message/key""


Recommended Posts

So i have tried to figure out how to make the script send a random message, got 3 different it should choose from.

So far i've tried this.

 

$x = Random(Lol,Goto)

Send($x)

Exit

Func Goto()
    Send("/goto 0", 1)
    Sleep(200)
    Send("{ENTER}", 0)
EndFunc


Func Lol()
Send("Lol", 1)
Sleep(200)
Send("{ENTER}",0)
EndFunc

Don't know what is wrong, well i started using AutoIT my first try on programming/scripting ever. So bare with me if it's something really simple Cheers. ;)

Link to comment
Share on other sites

You worked with Random in your previous thread - have you not read the help file?

Here's another example of what I would suggest:

Local $a[4] = ["a", "c", "g", "t"]
For $i = 1 To 10
    ConsoleWrite($a[Random(0, UBound($a) - 1, 1)])
Next

Try to understand what's going on here and translate it to your own script.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

29 minutes ago, Dequalityy said:

So i have tried to figure out how to make the script send a random message, ...

Well, try this:

ConsoleWrite("## Random-Test ##" & @CRLF)

For $i = 1 To 6
    Local $R = Random()
    Select
        Case $R < 0.333
            ConsoleWrite("Low  R=" & $R & @CRLF)
;~          Send("Something{ENTER}")
        Case $R < 0.666
            ConsoleWrite("Mid  R=" & $R & @CRLF)
;~          Send("Different{ENTER}")
        Case Else
            ConsoleWrite("High R=" & $R & @CRLF)
;~          Send("Whatever{ENTER}")
    EndSelect
    Sleep(500)
Next

ConsoleWrite("## Done ##" & @CRLF)
Exit

When running this script in SciTE, watch the output-window below the source.

To send text/keystrokes somewhere, you also need to have the correct window active.

-HaJo

Link to comment
Share on other sites

No, don't do that, that's bad advice (though well intended obviously :)). Because in that code the distribution is uneven, the numbers are hardcoded and thus easy to get wrong (QED) and it's laborious if you want to add another option later. Use the 3rd option for the Random() function to make it return integers, and if you use an array for the send strings and UBound() like I suggested, all you would need to do is simply add an element to the array.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

PM by Dequalityy:

9 minutes ago, Dequalityy said:

Sorry for pming u i know u told me not to, but for some freakin reason i can't reply to my topic... so i will try ask u here u can post my question & ur answer on the thread if u want to .. i just simply cant find a fkin reply button xD .. dunno whats going on with my firefox..

 

Local $a[4] = ["a", "c", "g", "t"] ; <- That line sets the amount of messages & messages to be sent correct me if wonrg.
For $i = 1 To 10 ; <- This line says it will be done 1 to 10 times ? 
    ConsoleWrite($a[Random(0, UBound($a) - 1, 1)]) ; <- You just simple made it write in console instead of in a active window correct?
Next ; <- SKips to next part of the script

 

Dequalityy.

As for your questions in the code:

  1. The first line creates an array with 4 elements. Have you read the array manual I linked to?
  2. For starts a loop (indeed, 10 times in this case) and Next ends the loop, so all code between For and Next will be looped. It only continues to the rest of the script after all loop iterations are completed (or if it is specifically instructed to exit the loop at some point).
  3. Yes, it writes to the console, but that's not the point, what I want you to get is why it writes what it writes (10x a random letter from the array).

The reply box is on the bottom of the thread. Try another browser if FF doesn't work for you (it works fine for me though).

Edited by SadBunny
Commented the comments in the code

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Dequalityy,

can you please tell us which program you try to automate? Sending keystrokes is not very reliable as the user might interfere with your script.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

4 hours ago, SadBunny said:

No, don't do that, that's bad advice (though well intended obviously :)).

Because in that code the distribution is uneven, the numbers are hardcoded

and thus easy to get wrong (QED) and it's laborious if you want to add another option later.

I want to argue that with my example, it is easier to see what is going on,

and you can adjust the distribution of random numbers any way you want.

-HaJo

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