Jump to content

I need a bit of help making random keystorkes...


 Share

Recommended Posts

I am trying to figure out how the If Then commands work with sleep.

For example if I said:

CODE
Sleep(1000 + Random(1, 9, 1))

I will get a sleep factor of 1001-1009

So I would like to tell it:

CODE
If sleep = 1009 Then

Send("{SPACE}")

So I thought it would look something like this :)

I would also use the If Then Else if possible:

CODE
$sleep(1000 + Random(1, 9 1))

If $sleep = 1009 Then

Send("{SPACE}")

ElseIf $sleep = 1001-1008 Then

Send("{TAB}")

Else

Send("{1}")

EndIf

the latter is preferable

I just can't seem to find out how to write that to make it work.

I keep getting to the second line of code and it says: $sleep^Error | Error: Expected a "=" Operator in assignment staement

So can someone help me understand this a bit?

Link to comment
Share on other sites

the sleep() function does not return the total amount of time spent "sleeping", and if it did you would need to get that data like $sleep=sleep(1000 + Random(1, 9, 1)), not $sleep(1000 + Random(1, 9, 1))

what you CAN do is this :)

$sleep=1000 + Random(1, 9, 1)
sleep($sleep)
if $sleep=1009... etcoÝ÷ Ù©l¢z-zØZ¶Ø^)Þjëh×6ElseIf $sleep = 1001-1008 Then oÝ÷ ÚÈhºW[y«­¢+Ù±Í%ÀÌØíͱÀÐìÄÀÀÀ¹ÀÌØíͱÀ±ÐìÄÀÀäQ¡¸oÝ÷ ÚÞDz¢ç(ºWcºË]¡«­¢+Ù±Í
Edited by improbability_paradox
Link to comment
Share on other sites

well you wrote down:

1008-1007

i think you meant BETWEEN these code, do this or that...

because, 1008-1001=7

The following operators are available:

=
>
<
>=
<=

extra's:
|| OR
>< (not equal)
Not
&& AND

if you want it between those numbers (1008-1001) you must do it like this:

$sleep = 1000 + random(1, 9, 1)
sleep($sleep)

If $sleep = 1009 Then
 MsgBox(0, "Answer", "The $sleep variable holds 1009!")
EndIf

If $sleep >= 1001 AND $sleep <= 1008 Then
 MsgBox(0, "Answer", "The $sleep variable holds a number between 1001 and 1008!" & " Number is " & $sleep)
EndIf

here it is,

-me

Edited by Immense
Link to comment
Share on other sites

Sweet... Thanks sooo much.

And I figured out how to get an extra feature by calling the last else by making the variable

$sleep < 1005 Then

That way 1006, 1007 and 1008 causes a 1 to be pushed

Coding is pretty fun :)

Sorry to sound noobish but I'm not very good at these things so when I learn something I jump up nd down lol

So this is what I ended up with and you're a lifesaver :D

CODE
While 1 = 1

$sleep=1000 + Random(1, 9, 1)

sleep($sleep)

if $sleep=1009 Then

Send("{SPACE}")

ElseIf $sleep > 1000 and $sleep < 1005 Then

Send("{TAB}")

Else

Send("{1}")

EndIf

Wend

But I also see what you mean if I just dropped the elsif and went straight to else...

Link to comment
Share on other sites

CODE
$sleep = 1000 + random(1, 9, 1)

sleep($sleep)

If $sleep = 1009 Then

MsgBox(0, "Answer", "The $sleep variable holds 1009!")

EndIf

If $sleep >= 1001 AND $sleep <= 1008 Then

MsgBox(0, "Answer", "The $sleep variable holds a number between 1001 and 1008!" & " Number is " & $sleep)

EndIf

and now I feel dumb again lol :">

I kinda get that but don't fully understand how that one works

Link to comment
Share on other sites

What part are you having a hard time with?

well I have the code I need but I would like to understand a few things about this code:

CODE
$sleep = 1000 + random(1, 9, 1)

sleep($sleep)If $sleep = 1009 Then

MsgBox(0, "Answer", "The $sleep variable holds 1009!")

EndIfIf $sleep >= 1001 AND $sleep <= 1008 Then

MsgBox(0, "Answer", "The $sleep variable holds a number between 1001 and 1008!" & " Number is " & $sleep)

EndIf

The first two line are the same but now we have "MsgBox" what does that do?

and what is "Answer" would that be where I put what I want it to do?

Link to comment
Share on other sites

The best answer you could get to that question, is to look up the entry for MsgBox in the helpfile. At the very least, it will be a more complete answer than the one I will give you here. Also, there are many options which can be set for this function, and you will need to look them up in order to understand them. But, in short...

the function MsgBox() creates a "Message Box". The characteristics of this Message Box are what is passed to the function. Lets dissect it a little

MsgBox(0,"Hello","This is my message box!")

the first parameter is a 0. this tells AutoIT what kind of message box to make. For example, what kind of buttons does it have, and how many? (some options could be buttons that say "OK","Cancel","Yes","No",etc...). Also, you can define certain icons to appear in the message box by using the correct codes. Look in the helpfile to find out more about what all of the numbers do, or just play around using different numbers in place of the 0.

The next parameter is "Hello". This is, simply enough, the title of the message box.

Now we have the text which comprises the actual message. in this case it is "This is my message box!"

message boxes stay open until one of the buttons is clicked. The script is also paused until the message box closes. You can use variables in the place of some or all of these parameters. Also, there is another parameter to define a timeout. Lastly, message boxes return a value depending on what button is clicked. to get this value, do something like this

$iMsg=MsgBox(0,"Hello","This is my message box!")
if $iMsg=... etc

hope this clears it up. When in doubt about what something does, look up the word in the helpfile (in this case, MsgBox)

Edited by improbability_paradox
Link to comment
Share on other sites

Ah, so it would create a pop up box? Kind of like a GUI?

I think I see then... In that case that's not really what I wanted but it's cool to know about it.

I wanted it to do it in the background without user interaction.

Am I right in assuming that code would require a users input? I.E. mouse or keyboard selection.

Kind of like:

CODE
MsgBox(4096, "Test", "This box will time out in 10 seconds", 10)

one more quick question that box has an ok button, is that default or is that the 4096 part?

4096 System modal (dialog has an icon) 0x1000

Edited by samsarai
Link to comment
Share on other sites

If you use MsgBox, then the answer is yes. Unless you specify a timeout, after which time the message box will close itself. But if you don't want to use a message box, just don't include that part of the code.

Edit: in response to your edit. the OK button, or any other button, depends completely on the first parameter. In this case, 4096 will include an OK button. Other options will have different buttons.

Edited by improbability_paradox
Link to comment
Share on other sites

If you use MsgBox, then the answer is yes. Unless you specify a timeout, after which time the message box will close itself. But if you don't want to use a message box, just don't include that part of the code.

Edit: in response to your edit. the OK button, or any other button, depends completely on the first parameter. In this case, 4096 will include an OK button. Other options will have different buttons.

Ok now I get it thanks for your patience and help :)

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