Can't Get Script To Randomize Keystroke

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kittycatgoesmeow
Posts: 1
Joined: 15 Oct 2021, 00:47

Can't Get Script To Randomize Keystroke

15 Oct 2021, 00:54

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!
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: Can't Get Script To Randomize Keystroke

15 Oct 2021, 01:41

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:
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
Rohwedder
Posts: 7705
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Can't Get Script To Randomize Keystroke

15 Oct 2021, 01:45

Hallo,
or shorter:

Code: Select all

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

Esc::ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: CoffeeChaton, LazyVovchik, rubeusmalfoy and 139 guests