Make Holding down different combination + Single key pr Topic is solved

Ask gaming related questions (AHK v1.1 and older)
QrJuicy
Posts: 1
Joined: 10 Apr 2024, 15:33
Contact:

Make Holding down different combination + Single key pr

Post by QrJuicy » 10 Apr 2024, 15:49

So I wanted to make :
- hold d + hold 2 + Left = combination 1
- hold a + hold 2 + Left = combination 2

Left button will have it's original function if none of the combinations above are held down.
For the context, I'm using this for a fighting game.

Code: Select all

; a move (facing right)
 if (GetKeyState(d))
 {
    if (GetKeyState(2))
    {
        Left::
        {
            global MidComboSleep := 1

            Send {d down}
            Sleep MidComboSleep
            Send {s down}
            Sleep MidComboSleep
            Send {d up}
            Sleep MidComboSleep
            Send {a down}
            Sleep MidComboSleep
            Send {s up}
            Sleep MidComboSleep
            Send {a up}
            Sleep MidComboSleep
            Send {d down}
            Sleep MidComboSleep
            Send {d up}
            Sleep MidComboSleep
            send {Left down}
            sleep MidComboSleep
            send {Lefts up}
            sleep MidComboSleep
            return
        }
    
    }
        
}

; a move (facing left)
 if (GetKeyState(a))
 {
    if GetKeyState(2)
    {
        Left::
        {
            global MidComboSleep := 1

            Send {a down}
            Sleep MidComboSleep
            Send {s down}
            Sleep MidComboSleep
            Send {a up}
            Sleep MidComboSleep
            Send {d down}
            Sleep MidComboSleep
            Send {s up}
            Sleep MidComboSleep
            Send {d up}
            Sleep MidComboSleep
            Send {a down}
            Sleep MidComboSleep
            Send {a up}
            Sleep MidComboSleep
            send {Left down}
            sleep MidComboSleep
            send {Left up}
            sleep MidComboSleep
            return
        }
    
    }
        
}
The error here is having duplicate key (Left ::).
If I merge them by using 1 (Left ::) and putting it at the topmost position in the nested ifs the code doesn't work.
If I use (~Left ::) instead the Left input is double, therefore the move won't be executed in-game.
How do I fix this?

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

Re: Make Holding down different combination + Single key pr  Topic is solved

Post by mikeyww » 10 Apr 2024, 21:34

Welcome to this AutoHotkey forum!

You need to reorganize your approach. Hotkeys with :: are never defined as part of If, but you can use a directive as shown in the example below. You do not need to test that with all of your Send and Sleep commands, because they are irrelevant to getting your hotkey to trigger. After you get a proper trigger, you can add the commands that you need. The example here shows how you can use two keys to define a context so that your mouse button is recognized in that context, but without actually sending the two keys during that period. The documentation explains custom combinations, so you can learn more there. You can create additional, different contexts for the same mouse button, with unique actions for each. The Hotkey command is another way to achieve this. GetKeyState does not wait for any key. Instead, the check is instantaneous.

Code: Select all

#Requires AutoHotkey v1.1.33.11

d::d
d & 2::
on := True
ToolTip % "===> ACTIVATED <==="
SoundBeep 1500
KeyWait d
KeyWait 2
Reset:
on := False
ToolTip
Return

#If on
LButton::
Gosub Reset
MsgBox
Return
#If
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.

Post Reply

Return to “Gaming Help (v1)”