1
votes

I am trying to make a very simple message spammer in AutoHotKey (just to have fun with friends)

(I've only found autohotkey recently and I am pretty knew to coding, so any feedback/improvements is welcomed, Thanks)

This is the code until now

#SingleInstance force 


^6::
Gui, Add, Text,  W200 +Center,"Message"
Gui, Add, Edit, W200 vTextt
Gui, Add, Text,  W200 +Center,"Number Of Messages"
Gui, Add, Edit, W200 vLooop
Gui, Add, Text,  W200 +Center,"Interval Between Messages"
Gui, Add, Edit, W200 vInterval


Gui, Add, Button, W200 gStart, Start Auto Spamming
Gui, Show
Return

Start:
Gui, Submit
Sleep, 5000
Loop, %Looop%
{   

    Send, %Textt% 
    Sleep, %Interval% * 1000
    Send, {Enter}
}
Gui, Destroy
Return
esc::exitapp

Its works fine right until

Sleep, %Interval% * 1000

this line

When I run the scrip it prompts me with the correct Gui For vTextt I put in my text For vLooop I put in the number of loops For vInterval I put in 1(as in 1 second)(delay between every message)

But in AutoHotKey 1 second must be written as 1000 (that is at least how I've been doing it)

So I multiply the variable(vInterval) with 1000 in the Sleep command , but the following error pops up

enter image description here

what do I do to fix this?(the delay doesn't occur and the message gets spammed instantly without any delay) I've tired to make another variable in which it multiplies but I do not know how variables work in autohotkey

Thank in advance

1

1 Answers

2
votes

When using a command that takes a number as the input (like Sleep, you do not need to enclose your numeric variables in parenthesis like %var% (As opposed to a command like Send that takes a text input in which you would need to do so in order to disambiguate it)

As such, you can remove the parenthesis surrounding your Interval variable in Sleep, %Interval% * 1000, so you end up with Sleep, Interval * 1000


Final Code:

#SingleInstance Force

^6::
Gui, Add, Text,  W200 +Center,"Message"
Gui, Add, Edit, W200 vTextt
Gui, Add, Text,  W200 +Center,"Number Of Messages"
Gui, Add, Edit, W200 vLooop
Gui, Add, Text,  W200 +Center,"Interval Between Messages"
Gui, Add, Edit, W200 vInterval


Gui, Add, Button, W200 gStart, Start Auto Spamming
Gui, Show
Return

Start:
Gui, Submit
Sleep, 5000
Loop, %Looop%
{   

    Send, %Textt% 
    Sleep, Interval * 1000
    Send, {Enter}
}
Gui, Destroy
Return
   
   
Esc::Exitapp