I am new to autohotkey and I used all the searching I could before posting this. I play BF2142 which requires you to hold down a button for your player to crouch, in every other game i play the crouch toggles. I am unable to get used to the nno toggle crouch in BF so I am looking for a script to make me crouch with the first press and then to uncrouch with the next press of the same key. The only script I have found was this
~LAlt up:: ;use LAlt "up" so it doesn't get triggered when you hold ctrl
Goto, Crouch
Crouch:
; Changed: Trigger was changed to "~LAlt" as ~ allows normal operation of key.
If (a_tickCount-lasttime < 400) ;Check when we released ctrl the last time if < 400ms initiate Crouch
{
Loop
{
Send, {LAlt down} ; Initiate 'Crouch'
If IsKeyPressed("LAlt") ; Check if 'LCtrl' pressed. If pressed & released, Break loop.
Send, {LAlt up} ; Release 'Crouch'
Break
}
}
lasttime:=a_tickCount
Return
IsKeyPressed(v_KeyName)
; Returns 1 if %v_KeyName% is currently being pressed, otherwise 0
{
GetKeyState, state, %v_KeyName%, P
If state = D ; The key has been pressed
{
Return 1
}
Return 0
}
The only problem with this is that it requires me to double tap the Left Alt key to crouch and then when I press it once more then I return to standing. They did it this way to keep the original funtion of the key so that you can still hold left alt and crouch as it is held. I do not care about the original function. I just want to press once and be crouched and once more un-crouched. I appreciate any help on this.Thanks!
Toggle key
Started by
Bobspanky
, Jul 04 2009 04:29 AM
8 replies to this topic
#1
-
Posted 04 July 2009 - 04:29 AM
How about this:
x = 1 <alt:: if x { sendinput {lalt down} x-- } else { sendinput {lalt up} x++ } return
#2
-
Posted 04 July 2009 - 06:54 AM
How about this?
Yes, they are identical.
<alt::SendInput, % "{LAlt " (X := !X ? "Down" : "Up") "}"
Yes, they are identical.
#3
-
Posted 04 July 2009 - 07:40 AM
As always, if you have any further questions, don't hesitate to ask.
Add OOP to your scripts via the Class Library. Check out my scripts.
Add OOP to your scripts via the Class Library. Check out my scripts.
They are not identical, your code works only once. It lacks a pair of parentheses:
<alt::SendInput, % "{LAlt " ((X := !X) ? "Down" : "Up") "}"
#4
-
Posted 04 July 2009 - 10:56 AM
Thanks everyone both scripts work perfectly!
x = 1
<alt::
if x {
sendinput {lalt down}
x--
}
else {
sendinput {lalt up}
x++
}
return
works 100%
and
<alt::SendInput, % "{LAlt " ((X := !X) ? "Down" : "Up") "}"
this is the one with extra parenthesis works 100%
very much appreciated.
Would it be possible to make this work for the "c" key and also include a thing to where if I press the left ctrl, the spacebar or shift that it comes out of the "c toggle" state to the c up position. This way when I am crouched if I go to sprint or lay prone or stand I do not first have to press c to untoggle crouch that it will just exit out of the toggle state. That way the game will perform exactly like all the other games usually do. Thanks again for such fast responses and help.
x = 1
<alt::
if x {
sendinput {lalt down}
x--
}
else {
sendinput {lalt up}
x++
}
return
works 100%
and
<alt::SendInput, % "{LAlt " ((X := !X) ? "Down" : "Up") "}"
this is the one with extra parenthesis works 100%
very much appreciated.
Would it be possible to make this work for the "c" key and also include a thing to where if I press the left ctrl, the spacebar or shift that it comes out of the "c toggle" state to the c up position. This way when I am crouched if I go to sprint or lay prone or stand I do not first have to press c to untoggle crouch that it will just exit out of the toggle state. That way the game will perform exactly like all the other games usually do. Thanks again for such fast responses and help.
#5
-
Posted 04 July 2009 - 03:26 PM
Not sure if this is exactly what you need, but try:
$c:: SendInput, % "{c " ((Y := !Y) ? "Down" : "Up") "}" ~Shift:: ~LCtrl:: ~Space:: SendInput, {c Up} Y = Return
#6
-
Posted 04 July 2009 - 05:33 PM
$c:: SendInput, % "{c " ((Y := !Y) ? "Down" : "Up") "}"
~Shift::
~LCtrl::
~Space::
SendInput, {c Up}
Y =
Return
works exactly how I wanted thanks once again!
~Shift::
~LCtrl::
~Space::
SendInput, {c Up}
Y =
Return
works exactly how I wanted thanks once again!
#7
-
Posted 04 July 2009 - 08:27 PM
Wow, thanks. I never knew the ternary operation had higher priority than assignment. However, it seems this holds true in other languages as well. Thanks a ton!They are not identical, your code works only once. It lacks a pair of parentheses:
<alt::SendInput, % "{LAlt " ((X := !X) ? "Down" : "Up") "}"
#8
-
Posted 04 July 2009 - 08:36 PM
As always, if you have any further questions, don't hesitate to ask.
Add OOP to your scripts via the Class Library. Check out my scripts.
Add OOP to your scripts via the Class Library. Check out my scripts.
<alt::SendInput, % "{LAlt " ((X := !X) ? "Down" : "Up") "}"
Cool! Thanks for this, just what I was looking for
#9
-
Posted 10 December 2011 - 12:41 AM