toggle pressed key Topic is solved

Ask gaming related questions (AHK v1.1 and older)
RicKami
Posts: 29
Joined: 08 Oct 2020, 06:55

toggle pressed key

Post by RicKami » 27 Jun 2022, 05:38

Hi,
In order to crouch in Borderlands 2 I need to hold the key pressed. I want to make a shortcut which would make the key to toggle. Meaning I press "C" once and the script holds it down so I stay crouched, when I press it again it releases it.
Is such thing possible?
I guess its easier to make another letter to make the C stay pressed and simply change the controls, so to avoid conflicts but, how do I make autohotkey to hold down a key and then don't conflict when I press it again?

If I use lets say M, then I press M and the scripts makes the C to stay down, then when I press M again the script "thinks" I am pressing CM together...
I tried with SHIFT but does not seem to work very well.
Any suggestion?
Thank you!

Code: Select all

!c::
c::
if mm=
{
 Send {LShift down}
 mm=1
}
else
{
 Send {LShift up}
 mm=
}
return

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

Re: toggle pressed key  Topic is solved

Post by mikeyww » 27 Jun 2022, 05:49

Test in Notepad.

Code: Select all

OnExit("reset")
c Up::
+c Up::
If !GetKeyState("LShift") {
 Send {LShift down}
 SoundBeep, 1500
} Else reset()
Return

reset(exitReason := "", exitCode := "") {
 Send {LShift up}
 SoundBeep, 1000
}

RicKami
Posts: 29
Joined: 08 Oct 2020, 06:55

Re: toggle pressed key

Post by RicKami » 27 Jun 2022, 06:19

Thank you mikeyww! This works beautifully! :-)
(with the sound too :D)

Post Reply

Return to “Gaming Help (v1)”