AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

toggle crouch for bf2142

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
zenuke



Joined: 23 Jan 2007
Posts: 11

PostPosted: Thu Jan 25, 2007 2:20 am    Post subject: toggle crouch for bf2142 Reply with quote

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.
Back to top
View user's profile Send private message
Zerohour250



Joined: 24 Jan 2007
Posts: 14

PostPosted: Thu Jan 25, 2007 3:53 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 2951
Location: Minnesota

PostPosted: Thu Jan 25, 2007 4:13 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Lanser



Joined: 24 Mar 2006
Posts: 20

PostPosted: Mon Jan 29, 2007 10:21 am    Post subject: Reply with quote

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.

Code:


~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
  }
Back to top
View user's profile Send private message
zenuke



Joined: 23 Jan 2007
Posts: 11

PostPosted: Mon Jan 29, 2007 3:39 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
YMP



Joined: 23 Dec 2006
Posts: 418
Location: Russia

PostPosted: Mon Jan 29, 2007 4:09 pm    Post subject: Reply with quote

Code:

MButton::
  If not D
  {
    Send, {Click down middle}
    D=1
  }
  Else
  {
    Send, {Click up middle}
    D=0
  }
Return
Back to top
View user's profile Send private message
zenuke



Joined: 23 Jan 2007
Posts: 11

PostPosted: Mon Jan 29, 2007 4:17 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
zenuke



Joined: 23 Jan 2007
Posts: 11

PostPosted: Mon Jan 29, 2007 11:10 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
YMP



Joined: 23 Dec 2006
Posts: 418
Location: Russia

PostPosted: Tue Jan 30, 2007 5:12 am    Post subject: Reply with quote

zenuke wrote:
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:
Code:

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.
Back to top
View user's profile Send private message
CC69



Joined: 27 Jul 2006
Posts: 26

PostPosted: Tue Jan 30, 2007 2:39 pm    Post subject: Reply with quote

BF2Enhance works with BF2142.

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

*Oh and for crouch toggle....

Code:
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
Back to top
View user's profile Send private message
nimda



Joined: 26 Dec 2010
Posts: 3856
Location: Awesometown, USA

PostPosted: Sat Mar 19, 2011 5:22 pm    Post subject: Reply with quote

Lanser wrote:
Code:

~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
Code:
~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. Crying or Very sad
_________________
Spam. Autoclick. Rapidfire.Window Control ToolsLicense
Back to top
View user's profile Send private message
Desi



Joined: 29 Oct 2010
Posts: 142
Location: Sydney, Australia

PostPosted: Thu Apr 28, 2011 3:39 am    Post subject: Reply with quote

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.

Code:
~LCtrl up::
  If (a_tickCount-lasttime < 300)
  {
      Send, {LCtrl down}
      If GetKeyState("LCtrl", "P")
        Send, {LCtrl up}
  }
  lasttime:=a_tickCount
Return
Back to top
View user's profile Send private message
Game_Tester_1993
Guest





PostPosted: Thu Apr 28, 2011 6:02 am    Post subject: Reply with quote

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
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group