Two binds with toggle function. Topic is solved

Ask gaming related questions (AHK v1.1 and older)
skumat0r
Posts: 5
Joined: 19 Mar 2024, 12:48

Two binds with toggle function.

Post by skumat0r » 19 Mar 2024, 13:03

Hello community , I'm new to ahk and I'm wondering if there is a solution to make a script where the bind Shift+W would turn on the spam of this bind and after pressing it again it would turn off the spam in the game and at the same time on Shift+S there would be another spam with the same properties and that one bind (Shift+W) would automatically turn off the other one (Shift+S) and vice versa. English is not my first language and I don't know how to describe it better. If someone could help me and need more information I would try to specify the details.
Thank you in advance.

User avatar
mikeyww
Posts: 26972
Joined: 09 Sep 2014, 18:38

Re: Two binds with toggle function.  Topic is solved

Post by mikeyww » 19 Mar 2024, 19:41

Welcome to this AutoHotkey forum!

Code: Select all

#Requires AutoHotkey v1.1.33.11
period := 30 ; Milliseconds

$+w::
$+s::
last := hk, hk := SubStr(A_ThisHotkey, 0)
If (on = period && hk = last) {
 SetTimer spam, % on := "Off"
 Return
} Else SetTimer spam, % on := period
Spam:
Send % hk
Return
If you are new to AHK, I recommend using its current version, which is v2, instead of this older deprecated version that is no longer developed.

skumat0r
Posts: 5
Joined: 19 Mar 2024, 12:48

Re: Two binds with toggle function.

Post by skumat0r » 22 Mar 2024, 04:50

First of all, I want to thank you for your help. Could it be possible to add to this script also the possibility to turn on and off the script with the Scroll lock key ? Regarding the recommendation to use a newer version of AHK , I was recommended this older version for the game I want to use this script in.

skumat0r
Posts: 5
Joined: 19 Mar 2024, 12:48

Re: Two binds with toggle function.

Post by skumat0r » 22 Mar 2024, 05:49

EDIT: (Should test it before the reply above.) While testing the script I found out that it doesn't work in-game, there are classic keyboard bindings in the game but you can also use bindings with modifiers and that's my goal.

User avatar
mikeyww
Posts: 26972
Joined: 09 Sep 2014, 18:38

Re: Two binds with toggle function.

Post by mikeyww » 22 Mar 2024, 06:54

You can try a new one-line test script that sends simple text to your target window, and does nothing more. If it fails, try running the script as admin. Some games block scripting. You can also try different key delays.

Code: Select all

#Requires AutoHotkey v1.1.33.11

F3::
SetKeyDelay 25, 25
SendEvent 123
Return

skumat0r
Posts: 5
Joined: 19 Mar 2024, 12:48

Re: Two binds with toggle function.

Post by skumat0r » 22 Mar 2024, 09:46

I didn't realize that I should have been more specific in the first reply because the script works but it only works when I open in-game chat (or text doc) and press bind, but outside of that where my binds Shift+w and Shift+s should trigger abilities on the action bar it doesn't do anything. Also there is one very important thing that I didn't mention in the OP and that is that after pressing a bind, say Shift+w, the spam of that bind is turned on until I press it again or press the bind Shift+s and make one bind turn off the other one. Even though I am an amateur in this I should have known better and in the first place described the OP in more detail.

I would like to share another script that I found online, this one requires you to hold the bind and turns on spam. Is it possible to add the same buttons to this script with the Shift modifier or change the "Hold_key" to toggle spam ?

Code: Select all

~2::Hold_Down("2")
~3::Hold_Down("3")
~4::Hold_Down("4")
~5::Hold_Down("5")
~e::Hold_Down("e")
~q::Hold_Down("q")
~f::Hold_Down("f")
~t::Hold_Down("t")

Hold_Down(key) {
    loop
    {
        GetKeyState, ScrollLockState, ScrollLock, T
 
        if (ScrollLockState = "U") {
            break
        } else {
        send %key%
            Sleep, 1
        GetKeyState, state, %key%, P
        if state = U ;
            break
        }
    }
    return
}
[Mod edit: Added [code][/code] tags. Please use them yourself when posting code!]

skumat0r
Posts: 5
Joined: 19 Mar 2024, 12:48

Re: Two binds with toggle function.

Post by skumat0r » 22 Mar 2024, 09:53

mikeyww wrote:
22 Mar 2024, 06:54
You can try a new one-line test script that sends simple text to your target window, and does nothing more. If it fails, try running the script as admin. Some games block scripting. You can also try different key delays.
This one works as intended.

User avatar
mikeyww
Posts: 26972
Joined: 09 Sep 2014, 18:38

Re: Two binds with toggle function.

Post by mikeyww » 22 Mar 2024, 13:49

I know nothing about an action bar. + indicates Shift. You can change the hotkeys as you like. Best of luck!

What the script does:
The bind Shift+W would turn on the spam of this bind and after pressing it again it would turn off the spam in the game and at the same time on Shift+S there would be another spam with the same properties and that one bind (Shift+W) would automatically turn off the other one (Shift+S) and vice versa.
If you game requires a longer key delay or press duration, that can be included in the script.

Post Reply

Return to “Gaming Help (v1)”