Sign in to follow this  
Followers 0
adm1

Randomizing key presses

9 posts in this topic

Hey guys, i am new at this and was wondering how you would write in the delay part to randomize the delays. Say i wanted to press space bar at random intervals. How would i do this? Thank you!

Share this post


Link to post
Share on other sites



I guess something like this might work:

$var = random(5000, 50000, 1)

While 1

Send("{space}")

Sleep($var)

WEnd

random(<min value>, <highest value>, 1)

Mine would do anything between 5 seconds and 50 seconds.


"I'm paper, rock is fine, nerf scissors!!!"

Share this post


Link to post
Share on other sites

It might be a bit easier to read

While 1
   Send("{space}")
   Sleep(1000*random(5, 50, 1))
WEnd

Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

Hello

I have a question along these lines so I thought I would post in this forum. Is it possible to enter random keys from the keyboard?

Sorry if this sounds kind of vague, by this I mean I want my script to do this:

Send ("{Random Keys (at least 7, but not more then 15) pressed, highlight what was just pressed, copy to clipboard}")

Sleep (5000)

Is this possible?

Share this post


Link to post
Share on other sites

SendRandomKeys()

Func SendRandomKeys()
    While 1
        Local $String
        Local $StringLen
        Local $Clip
        Local $Random = Random(7, 15, 1)
        Do
            $Chr = Random(32, 126, 1)
            $String = $String & Chr($Chr)
            $StringLen = StringLen($String)
        Until $StringLen = $Random
        $Clip = $Clip & $String & @CRLF
        ClipPut($Clip)
        Send($String)
        $String = ""
        Sleep(5000)
    WEnd
EndFunc


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks SmOke_N I will try this and report back.

:P It didn't work, I am getting an error

Line 0 (File "C:\Documents and Settings\ChOnG\Desktop\My Script.exe)

Func SendRandomKeys()

Error: "While" statement has no matching "Wend" statement.

Thanks for any help you can provide :lmao:

Edited by PopSmith

Share this post


Link to post
Share on other sites

Thanks SmOke_N I will try this and report back.

:P It didn't work, I am getting an error

Line 0 (File "C:\Documents and Settings\ChOnG\Desktop\My Script.exe)

Func SendRandomKeys()

Error: "While" statement has no matching "Wend" statement.

Thanks for any help you can provide :lmao:

I have made a slight mod to Smoke_N's script to add hotkeys

HotKeySet("{ESC}", "Terminate")
HotKeySet("{F9}", "SendRandomKeys")
While 1
    Sleep(100)
    WEnd

Func SendRandomKeys()
    While 1
        Local $String
        Local $StringLen
        Local $Clip
        Local $Random = Random(7, 15, 1)
        Do
            $Chr = Random(32, 126, 1)
            $String = $String & Chr($Chr)
            $StringLen = StringLen($String)
        Until $StringLen = $Random
        $Clip = $Clip & $String & @CRLF
        ClipPut($Clip)
        Send($String)
        $String = ""
        Sleep(5000)
    WEnd
EndFunc

Func Terminate()
    Exit 0
EndFunc

Run it in Beta, bring up notepad then hit F9 and see the results.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

You realize that the While 1...WEnd in the SendRandomKeys Func is probably going to produce unwanted output. Remove those two lines, and it might be more favorable


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

Hi guys, if you want you can look at my script, I am not sure how to get the random keys to function (sorry, I am a newbie :"> )

I attached the .au3 of the script with some notes on what I am trying to do.

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