Created
October 20, 2015 00:06
-
-
Save apsun/879e22fb47ff9f3cb763 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #NoEnv | |
| #Warn | |
| #NoTrayIcon | |
| #SingleInstance Force | |
| SendMode Input | |
| ;------------------------------------------------------------------------------- | |
| ;-------------------------------------Setup------------------------------------- | |
| ;------------------------------------------------------------------------------- | |
| MsgLines := 0 | |
| IsRunning := false | |
| ;------------------------------------------------------------------------------- | |
| ;--------------------------------------GUI-------------------------------------- | |
| ;------------------------------------------------------------------------------- | |
| Gui, Add, Edit, x12 y10 w250 h34 +Multi vMessage, | |
| Gui, Add, Text, x12 y57 w200 h17 , Interval between messages (milliseconds): | |
| Gui, Add, Edit, x222 y54 w40 h20 +Number +Limit vMsgInterval, | |
| Gui, Add, Text, x12 y81 w200 h17 , Interval between lines (milliseconds): | |
| Gui, Add, Edit, x222 y78 w40 h20 +Number +Limit vLineInterval, | |
| Gui, Add, Text, x12 y105 w250 h15 , Press F5 to toggle on/off the spammer! | |
| Gui, Add, Text, x12 y119 w250 h15 , Press F6 to send the text once! | |
| Gui, Show, w274 h143, AHKSpam v1.4 | |
| Return | |
| GuiEscape: | |
| GuiClose: | |
| ExitApp | |
| ;------------------------------------------------------------------------------- | |
| ;-----------------------------------F5 Hotkey----------------------------------- | |
| ;------------------------------------------------------------------------------- | |
| F5:: | |
| { | |
| If (!IsRunning) | |
| { | |
| ; Update the input | |
| Update() | |
| ; Check for empty message | |
| If (Message == "") | |
| { | |
| InfoMsgBox("You must enter some text to send!") | |
| Return | |
| } | |
| ; Ensure there is an interval and that it's positive | |
| If (MsgInterval <= 0) | |
| { | |
| InfoMsgBox("You must enter a positive interval between messages!") | |
| Return | |
| } | |
| ; Disable controls and set spam timer | |
| DisableControls() | |
| SetTimer, SendTimer, -%MsgInterval% | |
| } | |
| Else | |
| { | |
| ; Stop spamming, enable controls and disable spam timer | |
| EnableControls() | |
| SetTimer, SendTimer, Off | |
| } | |
| IsRunning := !IsRunning | |
| Return | |
| } | |
| ;------------------------------------------------------------------------------- | |
| ;-----------------------------------F6 Hotkey----------------------------------- | |
| ;------------------------------------------------------------------------------- | |
| F6:: | |
| { | |
| Update() | |
| If (Message == "") | |
| { | |
| InfoMsgBox("You must enter some text to send!") | |
| } | |
| Else | |
| { | |
| SendText(false) | |
| } | |
| Return | |
| } | |
| ;------------------------------------------------------------------------------- | |
| ;-------------------------------------Timer------------------------------------- | |
| ;------------------------------------------------------------------------------- | |
| SendTimer: | |
| { | |
| SendText(true) | |
| ; Hack: maintain the time between messages regardless of line count | |
| If (IsRunning) | |
| { | |
| SetTimer, SendTimer, -%MsgInterval% | |
| } | |
| } | |
| ;------------------------------------------------------------------------------- | |
| ;-----------------------------------Functions----------------------------------- | |
| ;------------------------------------------------------------------------------- | |
| InfoMsgBox(msg) | |
| { | |
| MsgBox,64,AHKSpam,%msg% | |
| } | |
| WarningMsgBox(msg) | |
| { | |
| MsgBox,48,AHKSpam,%msg% | |
| } | |
| Update() | |
| { | |
| Gui, Submit, NoHide | |
| Global MsgLines | |
| Global Message | |
| MsgLines := 0 | |
| Loop, Parse, Message, `n, `r | |
| { | |
| ++MsgLines | |
| } | |
| } | |
| DisableControls() | |
| { | |
| GuiControl, Disable, Message | |
| GuiControl, Disable, MsgInterval | |
| GuiControl, Disable, LineInterval | |
| } | |
| EnableControls() | |
| { | |
| GuiControl, Enable, Message | |
| GuiControl, Enable, MsgInterval | |
| GuiControl, Enable, LineInterval | |
| } | |
| SendText(auto) | |
| { | |
| Global MsgLines | |
| Global IsRunning | |
| Global Message | |
| Global LineInterval | |
| loopCount := 0 | |
| Loop, Parse, Message, `n, `r | |
| { | |
| SendInput {Raw}%A_LoopField% | |
| SendInput {Enter} | |
| If (LineInterval > 0 && ++loopCount < MsgLines) | |
| { | |
| Sleep %LineInterval% | |
| } | |
| If (auto && !IsRunning) | |
| { | |
| Return | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment