Help with my basic code

Ask gaming related questions
reecemod22
Posts: 6
Joined: 27 Jan 2016, 08:54

Help with my basic code

27 Jan 2016, 09:01

Im looking to make AHK hold down a key for 3 secs then hold down the next key for the same time then repeat

Code: Select all

[F1:: ; start
Loop 330
{
Send {w down}
Send {w up}
}
 Sleep 2000
Loop 331
{
Send {s down}
Send {s up}
}
 Sleep 2000]
Shadowpheonix
Posts: 1259
Joined: 16 Apr 2015, 09:41

Re: Help with my basic code

27 Jan 2016, 10:32

Does this work for you?

Code: Select all

#MaxThreadsPerHotkey 2    ; Allows you to use the same key to turn the loop on & off.
F12::    ; Key to start & stop the loop
Toggle := !Toggle    ; Switch the "Toggle" variable between true & false
While Toggle    ; Loop while the "Toggle" variable is true
{
    Send {w down}    ; Hold the W key down.
    Sleep 3000    ; Wait 3000 milliseconds.
    Send {w up}    ; Release the W key.
    If !Toggle    ; Abort the next key if "Toggle" is now false
        Break
    Send {s down}    ; Hold the S key down.
    Sleep 3000    ; Wait 3000 milliseconds
    Send {s up}    ; Release the S key.
}
Return    ; Marks the end of the F12 hotkey code.
reecemod22
Posts: 6
Joined: 27 Jan 2016, 08:54

Re: Help with my basic code

27 Jan 2016, 21:30

thanks man it works perfect i just need to get this auto click working and im set im just trying to add a 4-5 sec interval between clicks and ill have to
reecemod22
Posts: 6
Joined: 27 Jan 2016, 08:54

Re: Help with my basic code

27 Jan 2016, 21:39

just wanna add this without interupting the original keystring i cant get it


F8::Toggle := !Toggle

Click:
If (!Toggle)
Return
Click
Send a
return
Shadowpheonix
Posts: 1259
Joined: 16 Apr 2015, 09:41

Re: Help with my basic code

28 Jan 2016, 09:23

You can't use the "Toggle" variable for two different hotkeys that way without having them affect each other. Instead, make the variable name unique to each hotkey. Something like this...

Code: Select all

#MaxThreadsPerHotkey 2    ; Allows you to use the same key to turn the loop on & off.

F12::    ; Key to start & stop the loop
F12Toggle := !F12Toggle    ; Switch the "Toggle" variable between true & false
While F12Toggle    ; Loop while the "Toggle" variable is true
{
    Send {w down}    ; Hold the W key down.
    Sleep 3000    ; Wait 3000 milliseconds.
    Send {w up}    ; Release the W key.
    If !F12Toggle    ; Abort the next key if "Toggle" is now false
        Break
    Send {s down}    ; Hold the S key down.
    Sleep 3000    ; Wait 3000 milliseconds
    Send {s up}    ; Release the S key.
}
Return    ; Marks the end of the F12 hotkey code.

; Here's your F8 & Click code with only the variable name changed.
; As written, the "Click:" label is never called, so it does not actually do anything.
; I am not sure how you want to use it, so I made no other changes.
F8::F8Toggle := !F8Toggle

Click:
If (!F8Toggle)
Return
Click
Send a
return

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 11 guests