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
Please help with button spamming Topic is solved
Re: Please help with button spamming Topic is solved
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.
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
#SingleInstance, force
SetKeyDelay, 0, 50 ; The 50 controls how long each key is held for.
SetTitleMatchMode, 2
DetectHiddenWindows, On
SpamRate := 150 ; Change this to send the rate at which keys are spammed
return
sendkey() {
if (!WinActive("Diablo")){
return ; While Diablo is not the active window, don't spam keys
}
send w
send a
}
f2::
toggle := !toggle
settimer sendkey, % toggle ? SpamRate : "off"
return
Re: Please help with button spamming
You are amazing! thank you so much! I really appreciate your hard work in fixing my borrowed code.
Re: Please help with button spamming
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
#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
Re: Please help with button spamming
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.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]
Code: Select all
#ifWinActive,Diablo III
#MaxThreadsPerHotkey 2
;#Persistent
setkeydelay 5
toggle := false
return
F1::
toggle := !toggle
if (toggle) {
SetTimer,Send4,10
} else {
SetTimer,Send4,Off
}
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
Re: Please help with button spamming
One lazy way to do it is to reload the script, this would force the current code to stop.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
#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
This is easy to do, you only need to put the following code to reload the script:
Code: Select all
Reload
Code: Select all
F1::
toggle := !toggle
if (toggle) {
SetTimer,Send4,10
} else {
Reload; <--- Makes the script reload, hence stoping whatever the code is doing
;SetTimer,Send4,Off
;toggle := false
;break
} ;Send, {3 Up}
;KeyWait F1
return
Re: Please help with button spamming
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.
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.
Who is online
Users browsing this forum: Bing [Bot] and 62 guests