Page 1 of 1

Can't Get Script To Randomize Keystroke

Posted: 15 Oct 2021, 00:54
by kittycatgoesmeow
So I've never written a script before. What I want is really basic; I just want it to click "e" every 4-5 seconds. I also tried to get the script to stop after hitting the esc key. I can't seem to get the random function to work. After a fair amount of research, here's what I have:

Code: Select all

#Persistent
SetTimer, PressTheKey, 4000
Return

PressTheKey:
Send, {e}
Random, rand, 4000, 5000
Return

Esc::ExitApp


All help is much appreciated!

Re: Can't Get Script To Randomize Keystroke

Posted: 15 Oct 2021, 01:41
by Masonjar13
The random command is working, but you're not using the output of it, which would be the variable rand.

Code: Select all

#Persistent
SetTimer, PressTheKey, 4000
Return

PressTheKey:
Send, {e}
Random, rand, 4000, 5000
SetTimer, PressTheKey,% rand
Return

Esc::ExitApp
You can use % followed by a space to force expression mode in commands, which in this case means to use text as a variable reference instead.

Everything else is just fine, so good job on your first script :thumbup:

Re: Can't Get Script To Randomize Keystroke

Posted: 15 Oct 2021, 01:45
by Rohwedder
Hallo,
or shorter:

Code: Select all

PressTheKey:
Send, {e}
Random, rand, 4000, 5000
SetTimer, PressTheKey,% rand
Return

Esc::ExitApp