Key Spam macro help.

Ask gaming related questions
Brian2one0
Posts: 4
Joined: 19 Jan 2016, 05:20

Key Spam macro help.

19 Jan 2016, 06:09

So I'm currently using an AutoHotkey Script my friend made a long time ago and It worked for what he made it for. Now I need it to spam 2 buttons (or 3 or 4 etc) and I was wondering how to do that. Currently this is what I'm using (idk if this is the best way to set it up or not so if there is a better way to do it that would be awesome)

Code: Select all

; Press [F1] to start spamming
; >>> CUSTOMIZING <<<
;
; Change the values below to match your setup.

; SWToggleKey -- Key that toggles spamming on/off (Default "*F1", read:F1
; key with any modifier)
SWToggleKey := "*F1"

; explosive blast
; Wind key (Default "4")
SWKey := "E"

; LoopIntervalMin -- Minimum time in milliseconds between loops (Default 1000)
; NOTE: Strongly recommended you do not set this below 100
LoopIntervalMin := 850

; LoopIntervalMax -- Maximum time in milliseconds between loops (Default 1500)
LoopIntervalMax := 880

; Limit scope of all hotkeys below to Diablo3 window
#ifwinactive ahk_class D3 Main Window Class
Hotkey, IfWinActive, ahk_class D3 Main Window Class

GoSub, Init
Return

; Set everything up
Init:
    _EnableSW := False
    HotKey,%SWToggleKey%,ToggleSW

    SetKeyDelay, 33, 0
    Return

; SW enable/disable
ToggleSW:
    _EnableSW := !_EnableSW
    If _EnableSW {
        SetTimer AutoLoop, On
    }

    Return

; The actual spam loop
AutoLoop:
    While _EnableSW
    {
        If WinActive("ahk_class D3 Main Window Class")
        {
            Send %SWKey%
        }
        Random, random, %LoopIntervalMin%, %LoopIntervalMax%
        Sleep %random%
    }
    Return

#ifwinactive
So where it says "explosive blast" I tried to copy and paste that command directly below it and add a separate key but that didn't work and it just only spammed the first key. How would I go about adding multiple keys to be pressed whenever I press the hotkey to turn the macro on?
User avatar
evilC
Posts: 4783
Joined: 27 Feb 2014, 12:30

Re: Key Spam macro help.

19 Jan 2016, 08:03

Code: Select all

; Press [F1] to start spamming
; >>> CUSTOMIZING <<<
;
; Change the values below to match your setup.
 
; SWToggleKey -- Key that toggles spamming on/off (Default "*F1", read:F1
; key with any modifier)
SWToggleKey := "*F1"
 
; explosive blast
; Wind key (Default "4")
WindKey := "4"
SWKey := "E"
 
; LoopIntervalMin -- Minimum time in milliseconds between loops (Default 1000)
; NOTE: Strongly recommended you do not set this below 100
LoopIntervalMin := 850
 
; LoopIntervalMax -- Maximum time in milliseconds between loops (Default 1500)
LoopIntervalMax := 880
 
; Limit scope of all hotkeys below to Diablo3 window
#ifwinactive ahk_class D3 Main Window Class
Hotkey, IfWinActive, ahk_class D3 Main Window Class
 
GoSub, Init
Return
 
; Set everything up
Init:
    _EnableSW := False
    HotKey,%SWToggleKey%,ToggleSW
 
    SetKeyDelay, 33, 0
    Return
 
; SW enable/disable
ToggleSW:
    _EnableSW := !_EnableSW
    If _EnableSW {
        SetTimer AutoLoop, On
    }
 
    Return
 
; The actual spam loop
AutoLoop:
    While _EnableSW
    {
        If WinActive("ahk_class D3 Main Window Class")
        {
            Send % "{" SWKey "}{" WindKey "}"
        }
        Random, random, %LoopIntervalMin%, %LoopIntervalMax%
        Sleep %random%
    }
    Return
 
#ifwinactive
User avatar
evilC
Posts: 4783
Joined: 27 Feb 2014, 12:30

Re: Key Spam macro help.

19 Jan 2016, 08:07

or to make it work with any number of keys:

Code: Select all

; Press [F1] to start spamming
; >>> CUSTOMIZING <<<
;
; Change the values below to match your setup.
 
; SWToggleKey -- Key that toggles spamming on/off (Default "*F1", read:F1
; key with any modifier)
SWToggleKey := "*F1"
 
; explosive blast
; Wind key (Default "4")
SendString := "{e}{4}{Space}"	; add as many keys to the string as you like...
 
; LoopIntervalMin -- Minimum time in milliseconds between loops (Default 1000)
; NOTE: Strongly recommended you do not set this below 100
LoopIntervalMin := 850
 
; LoopIntervalMax -- Maximum time in milliseconds between loops (Default 1500)
LoopIntervalMax := 880
 
; Limit scope of all hotkeys below to Diablo3 window
#ifwinactive ahk_class D3 Main Window Class
Hotkey, IfWinActive, ahk_class D3 Main Window Class
 
GoSub, Init
Return
 
; Set everything up
Init:
    _EnableSW := False
    HotKey,%SWToggleKey%,ToggleSW
 
    SetKeyDelay, 33, 0
    Return
 
; SW enable/disable
ToggleSW:
    _EnableSW := !_EnableSW
    If _EnableSW {
        SetTimer AutoLoop, On
    }
 
    Return
 
; The actual spam loop
AutoLoop:
    While _EnableSW
    {
        If WinActive("ahk_class D3 Main Window Class")
        {
            Send % SendString
        }
        Random, random, %LoopIntervalMin%, %LoopIntervalMax%
        Sleep %random%
    }
    Return
 
#ifwinactive
Brian2one0
Posts: 4
Joined: 19 Jan 2016, 05:20

Re: Key Spam macro help.

19 Jan 2016, 15:26

evilC wrote:or to make it work with any number of keys:

Code: Select all

; Press [F1] to start spamming
; >>> CUSTOMIZING <<<
;
; Change the values below to match your setup.
 
; SWToggleKey -- Key that toggles spamming on/off (Default "*F1", read:F1
; key with any modifier)
SWToggleKey := "*F1"
 
; explosive blast
; Wind key (Default "4")
SendString := "{e}{4}{Space}"	; add as many keys to the string as you like...
 
; LoopIntervalMin -- Minimum time in milliseconds between loops (Default 1000)
; NOTE: Strongly recommended you do not set this below 100
LoopIntervalMin := 850
 
; LoopIntervalMax -- Maximum time in milliseconds between loops (Default 1500)
LoopIntervalMax := 880
 
; Limit scope of all hotkeys below to Diablo3 window
#ifwinactive ahk_class D3 Main Window Class
Hotkey, IfWinActive, ahk_class D3 Main Window Class
 
GoSub, Init
Return
 
; Set everything up
Init:
    _EnableSW := False
    HotKey,%SWToggleKey%,ToggleSW
 
    SetKeyDelay, 33, 0
    Return
 
; SW enable/disable
ToggleSW:
    _EnableSW := !_EnableSW
    If _EnableSW {
        SetTimer AutoLoop, On
    }
 
    Return
 
; The actual spam loop
AutoLoop:
    While _EnableSW
    {
        If WinActive("ahk_class D3 Main Window Class")
        {
            Send % SendString
        }
        Random, random, %LoopIntervalMin%, %LoopIntervalMax%
        Sleep %random%
    }
    Return
 
#ifwinactive
Thanks man this is awesome! I have a question though, what does the "SWKey" and "WindKey" mean? Are they different at all? Because in the script it says a whole bunch of "EnableSW"
User avatar
evilC
Posts: 4783
Joined: 27 Feb 2014, 12:30

Re: Key Spam macro help.

19 Jan 2016, 15:36

SWKey and WindKey are just variables that hold key names. Note that in my second example, Wind Key is not used, it is just a comment:
This does nothing: ; Wind key (Default "4")
The second version I posted is the simplest, having two variables in the first version is kind of pointless.
Brian2one0
Posts: 4
Joined: 19 Jan 2016, 05:20

Re: Key Spam macro help.

19 Jan 2016, 16:55

evilC wrote:SWKey and WindKey are just variables that hold key names. Note that in my second example, Wind Key is not used, it is just a comment:
This does nothing: ; Wind key (Default "4")
The second version I posted is the simplest, having two variables in the first version is kind of pointless.
Yeah I'm currently using the second version, didn't know it was that simple to have multiple key presses. Thanks a lot man I really appreciate it.

Does it matter though if it's called SWKey or WindKey? Like I could called it EBlastKey if i wanted too, I would just have to change everything that says "SWenable" to "EBlastEnable" ?
Brian2one0
Posts: 4
Joined: 19 Jan 2016, 05:20

Re: Key Spam macro help.

19 Jan 2016, 18:04

evilC wrote:yup, the name is unimportant, as long as you use the same name to refer to the same variable ;)
case is unimportant
Alright thanks! You've been a great help and I really appreciate it man.

Return to “Gaming”

Who is online

Users browsing this forum: kevolusean and 18 guests