Randoms

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sterger7
Posts: 7
Joined: 30 Sep 2019, 18:04

Randoms

06 Mar 2020, 19:19

Hi all...so I have this very basic script which turn son with f 11 off with f 12 and sends the "8" key to the active window every (however many seconds I want). I'm trying to understand how randomizers work?
For example....how would I modify this if I wanted it to send "random" keystrokes from a list (like 1-8 for example) at a random interval of seconds?

F11::
BreakLoop := 0
Loop
{
if BreakLoop = 1
break
send {8}
sleep 180000
}
return
F12::
BreakLoop := 1
return
kyuuuri
Posts: 340
Joined: 09 Jan 2016, 19:20

Re: Randoms

06 Mar 2020, 20:15

Hello, remember to use code tags to show your code.

You can use:
keys := [1,2,3,4,5,6,7,8]

and inside the loop you can do a random that goes from 1 to keys' max index:

Code: Select all

random, rand, 1, % keys.maxIndex()
send % keys[rand]
That will "pick" a random element from the array keys and send it.
sterger7
Posts: 7
Joined: 30 Sep 2019, 18:04

Re: Randoms

06 Mar 2020, 20:34

Thanks, and is there a way to randomize the timer aspect? The delay
kyuuuri
Posts: 340
Joined: 09 Jan 2016, 19:20

Re: Randoms

06 Mar 2020, 21:11

Same way:

Code: Select all

random, rand, minValue, maxValue
sleep % rand
sterger7
Posts: 7
Joined: 30 Sep 2019, 18:04

Re: Randoms

07 Mar 2020, 00:20

Code: Select all

F11::
keys := [1,2,3,4,5,6,7,8]
BreakLoop := 0
Loop 
{
if BreakLoop = 1
  break 
random, rand, 1, % keys.maxIndex()
send % keys[rand]
random, rand, 1000, 20000
sleep % rand
}
return

F12::
BreakLoop := 1
return
Think I missed something up, doesn't seem to work now.
sterger7
Posts: 7
Joined: 30 Sep 2019, 18:04

Re: Randoms

07 Mar 2020, 00:26

it might be working need to test here

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ccqcl, Descolada, inseption86, mebelantikjaya and 344 guests