Please help with button spamming Topic is solved

Ask gaming related questions
peadyj
Posts: 2
Joined: 18 Apr 2018, 18:11

Please help with button spamming

18 Apr 2018, 18:20

Hi Guys, I don't understand AHK scripting at all, i've read quite a few of other peoples posts and cut and copped bits form a few to try and make what i GUESS is a script that i want?
Can someone please check it and fix it for me? lol

I want the script to work like this, if Diablo is the ACTIVE window then run the commands, if i click out of the window to my 2nd screen (which happens quite often, pause until the window is active again...eg i click back into it, then continue spamming the buttons without having to repress F2)
F2 starts the script and spam clicks "w" and "a" keys until F2 is pressed again. i'm not sure what the settimer 50 is, i assume 50ms per click? i think maybe i should change that to 150 or so?



#MaxThreadsPerHotkey, 2
SetTitleMatchMode, 2
DetectHiddenWindows, On

#If (WinActive("Diablo"))

return

sendkey() {
send w
send a
}


f2::
toggle := !toggle
settimer sendkey, % toggle ? "50" : "off"
return

#if
User avatar
evilC
Posts: 4277
Joined: 27 Feb 2014, 12:30

Re: Please help with button spamming  Topic is solved

19 Apr 2018, 12:27

The #IfWinActive code that you had only enabled / disabled the start / stop hotkey, it had zero effect on the spam loop if it was already running.
This version uses WinActive() to check if the window is active before sending any keys.
You can still start/stop the macro whether the window is active or not, it just won't send any keys while the window isn't active.

I also added a "SpamRate" variable to make it easy to change the rate the keys are sent at.
You are correct in assuming that 50 is probably too fast. Many games do not like keys sent too fast.
Typically the problem is not sending the key presses too fast, it's that there needs to be a delay between the press and release of the key. The AHK command SetKeyDelay, 0, 50 ensures that your Send a holds a for at least 50ms before releasing it, so I added that for you.
So seeing as you are sending two keys (Which may take up to 100ms), then 150 (A pause of 50 between each round of spamming) would be about right IMHO.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

peadyj
Posts: 2
Joined: 18 Apr 2018, 18:11

Re: Please help with button spamming

19 Apr 2018, 18:51

You are amazing! thank you so much! I really appreciate your hard work in fixing my borrowed code.
Oleg

Re: Please help with button spamming

20 Apr 2018, 02:33

Can u help me, i have this script, but when i press F1 again after run this script, it continues to run until the end of the whole cycle, I want that when I press the F1 / off key, it stops executing instantly without waiting for the completion of the execution.

#ifWinActive,Diablo III
#MaxThreadsPerHotkey 2
;#Persistent
setkeydelay 5
toggle := false
return

F1::
toggle := !toggle
if (toggle) {
SetTimer,Send4,10
} else {
SetTimer,Send4,Off
;toggle := false
;break
} ;Send, {3 Up}

;KeyWait F1

return

Send4:
Send 4
Sleep 450
Send {1 Down}
Sleep 1700
Send {1 Up}
Send 2
Sleep 450
Send {1 Down}
Sleep 600
Send {1 Up}
Send {3 Down}
Sleep 267
Send {3 Up}
Return
Oleg

Re: Please help with button spamming

20 Apr 2018, 09:26

evilC wrote:The #IfWinActive code that you had only enabled / disabled the start / stop hotkey, it had zero effect on the spam loop if it was already running.
[/code]


Please help me, rework this script, when i press F1 again after run this script, it continues to run until the end of the whole cycle, I want that when I press the F1 (swith off key), it stops executing instantly without waiting for the completion of the execution.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Acuena
Posts: 20
Joined: 27 Jan 2014, 14:56

Re: Please help with button spamming

20 Apr 2018, 09:42

Oleg wrote:Can u help me, i have this script, but when i press F1 again after run this script, it continues to run until the end of the whole cycle, I want that when I press the F1 / off key, it stops executing instantly without waiting for the completion of the execution.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



One lazy way to do it is to reload the script, this would force the current code to stop.
This is easy to do, you only need to put the following code to reload the script:


So, if I don't mess it up, would be like this for the F1 key:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Ow and next time you post a question, plz do so in a new post. It could be tricky if you hijack someones thread. It also makes it easier to see if you answers the thread.
User avatar
evilC
Posts: 4277
Joined: 27 Feb 2014, 12:30

Re: Please help with button spamming

20 Apr 2018, 12:09

Further to Acuena's post, you can use Pause to pause the *whole* script.
As long as while the spam loop is off, there is no other code running, this would allow you to pause and unpause the script with a hotkey.

However, if you pause then unpause, it will resume where it left off, mid-loop, so you might not want that.

The only real other option is to add a check of the value of toggle before every line of the send.

Return to “Gaming”

Who is online

Users browsing this forum: scriptors and 7 guests