AutoHotkey Community

It is currently May 24th, 2012, 3:14 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: toggle crouch for bf2142
PostPosted: January 25th, 2007, 3:20 am 
Offline

Joined: January 23rd, 2007, 2:36 pm
Posts: 11
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2007, 4:53 am 
Offline

Joined: January 24th, 2007, 2:35 am
Posts: 14
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2007, 5:13 am 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 29th, 2007, 11:21 am 
Offline

Joined: March 24th, 2006, 4:15 pm
Posts: 20
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
  }


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 29th, 2007, 4:39 pm 
Offline

Joined: January 23rd, 2007, 2:36 pm
Posts: 11
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 29th, 2007, 5:09 pm 
Offline

Joined: December 23rd, 2006, 6:02 pm
Posts: 424
Location: Russia
Code:
MButton::
  If not D
  {
    Send, {Click down middle}
    D=1
  }
  Else
  {
    Send, {Click up middle}
    D=0
  }
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 29th, 2007, 5:17 pm 
Offline

Joined: January 23rd, 2007, 2:36 pm
Posts: 11
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 30th, 2007, 12:10 am 
Offline

Joined: January 23rd, 2007, 2:36 pm
Posts: 11
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 30th, 2007, 6:12 am 
Offline

Joined: December 23rd, 2006, 6:02 pm
Posts: 424
Location: Russia
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 30th, 2007, 3:39 pm 
Offline

Joined: July 27th, 2006, 2:34 pm
Posts: 26
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2011, 6:22 pm 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4170
Location: Awesometown, USA
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. :cry:

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 28th, 2011, 4:39 am 
Offline

Joined: October 29th, 2010, 5:58 am
Posts: 143
Location: Sydney, Australia
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 28th, 2011, 7:02 am 
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


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Cerberus, DetroitAutoHotkey, engunneer, Google Feedfetcher, Pulover and 22 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group