Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

toggle crouch for bf2142


  • Please log in to reply
12 replies to this topic
zenuke
  • Members
  • 11 posts
  • Last active: Jan 29 2007 11:09 PM
  • Joined: 23 Jan 2007
I have tried many of the suggestions here but I cant seem to get any to work. I am trying to make my middle mouse button a toggle for crouch. I'm sick of holding it down. so far the 3 scrips I have ried did not work.

Zerohour250
  • Members
  • 14 posts
  • Last active: May 11 2008 11:06 PM
  • Joined: 24 Jan 2007
If you want to not hold anything dow may i suggest scroll lock or Caps lock or Num Lock
because you will need to hold down middle mouse button

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004
No you don't. You can send a {Key down}, and then a {Key up} later on.

@zenuke: You need to be more specific about what has to be done to crouch. Most importantly, the key that actually does it.

Lanser
  • Members
  • 20 posts
  • Last active: Feb 01 2007 09:21 PM
  • Joined: 24 Mar 2006
I don't use this anymore but it works. The trigger is a double tap of control to initiate a toggle crouch, an ordinary press works as a press and hold crouch. Just crouch and release to toggle off crouch.


~LCtrl up::                        ;use LCtrl "up" so it doesn't get triggered when you hold ctrl
  Goto, Crouch

Crouch:
  ; Changed: Trigger was changed to "~LCtrl" 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, {LCtrl down}            ; Initiate 'Crouch'
      If IsKeyPressed("LCtrl")         ; Check if 'LCtrl' pressed. If pressed & released, Break loop.
        Send, {LCtrl 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
  }


zenuke
  • Members
  • 11 posts
  • Last active: Jan 29 2007 11:09 PM
  • Joined: 23 Jan 2007
I use the middle mouse button in the game as the crouch action. You normally need to hold down whatever key you have set in order to stay crouched. I would like to eliminate having to hold the button down.

If I can click the middle button and have it act as if its being held down, thats what I want. When I click the button again, it acts as if I let go.

the things I've tried do not work. I end up not being able to crouch at all.

YMP
  • Members
  • 424 posts
  • Last active: Apr 05 2012 01:18 AM
  • Joined: 23 Dec 2006

MButton::

  If not D

  {

    Send, {Click down middle}

    D=1

  }

  Else

  {

    Send, {Click up middle}

    D=0

  }

Return



zenuke
  • Members
  • 11 posts
  • Last active: Jan 29 2007 11:09 PM
  • Joined: 23 Jan 2007
YMP i'll give that a try but it looks very similar to something I've already tried. I'll let you know how it goes later.

zenuke
  • Members
  • 11 posts
  • Last active: Jan 29 2007 11:09 PM
  • Joined: 23 Jan 2007
didnt work, same thing happened as other scripts. I click once and nothing happens. I could still duck with this one by holding the key down.

YMP
  • Members
  • 424 posts
  • Last active: Apr 05 2012 01:18 AM
  • Joined: 23 Dec 2006

I could still duck with this one by holding the key down.

This looks like the game intercepts mouse events, so that they are invisible to AutoHotkey; therefore the code for MButton is never run.
You can try another method of the middle click detection:
Loop
{
  KeyWait, MButton, D
  KeyWait, MButton
  Send, {Click down middle}
  SoundBeep
  KeyWait, MButton, D
  KeyWait, MButton
  Send, {Click up middle}
  SoundBeep
  SoundBeep
}
Also SendPlay may be better instead of Send. I inserted SoundBeeps into the code so that you can hear if AutoHotkey sees you press the button.

CC69
  • Members
  • 26 posts
  • Last active: Jun 23 2009 03:58 PM
  • Joined: 27 Jul 2006
BF2Enhance works with BF2142.

Crouch Toggle, Quick Weapon Switch, Quick Weapon Scroll, Iron Sights, Enable Paste.

*Oh and for crouch toggle....

state=up
SetKeyDelay, -1, 100

Hotkey, {KEY} , Run
return

Run:
if state = up
{
Send, {KEY down}
state=down
}
else
{
Send, {KEY up}
state=up
}
return


nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010

~LCtrl up::                        ;use LCtrl "up" so it doesn't get triggered when you hold ctrl
  Goto, Crouch

Crouch:
  ; Changed: Trigger was changed to "~LCtrl" 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, {LCtrl down}            ; Initiate 'Crouch'
      If IsKeyPressed("LCtrl")         ; Check if 'LCtrl' pressed. If pressed & released, Break loop.
        Send, {LCtrl 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
  }

Is the same exact thing as
~LCtrl up::
  If (a_timeSinceThisHotkey < 400)
    {
      Send, {LCtrl down}
      If GetKeyState("LCtrl","P")
        Send, {LCtrl up}
    }
Return
Due to the redundant function, redundant Goto, and the loop that doesn't loop.

Sorry for gravedigging, but seeing that code hurt me inside. :cry:

Desi
  • Members
  • 162 posts
  • Last active: Apr 15 2015 09:51 AM
  • Joined: 29 Oct 2010
Just tried your code, nimda, and while it is logically the same, it does NOT do the same thing. It seems that AHK has trouble with a_timeSinceThisHotkey when applied to a tilded hotkey. You will find that if you run your code, it will not release the key when you try to toggle it off.

Keeping a_tickCount makes it work perfectly.

~LCtrl up::
  If (a_tickCount-lasttime < 300)
  {
      Send, {LCtrl down}
      If GetKeyState("LCtrl", "P")
        Send, {LCtrl up}
  }
  lasttime:=a_tickCount
Return


Game_Tester_1993
  • Guests
  • Last active:
  • Joined: --
ok i seriously have to ask, people still play BF 2142? off topic i know but seriously i thought it's community died out, well at least 90% of the australian community went to BC 2 which will all be moving to BF3 within a year or 2 after it's release