AutoHotkey Community

It is currently May 27th, 2012, 9:39 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 33 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: October 20th, 2006, 7:13 am 
Offline

Joined: October 20th, 2006, 6:57 am
Posts: 33
hi im trying to get battlefield 2142 crouch to work when you press the button the guy stays crouched like bf2 and now he dosent i tred many many scripts that dont work..someone please help me...this is what i got and it needs help

thanks

Code:
c::
      Send, {c down}            ; Initiate 'Crouch'
      If IsKeyPressed("c")         ; Check if 'c' pressed. If pressed & released, Break loop.
        Send, {c up}            ; Release 'Crouch'



c is my crouch button btw...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2006, 7:26 am 
Offline

Joined: March 11th, 2006, 12:44 pm
Posts: 341
Location: Munich, Germany
you should try it similar to this:

http://www.autohotkey.com/forum/viewtop ... 2530#82530


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2006, 7:34 am 
Offline

Joined: October 20th, 2006, 6:57 am
Posts: 33
i was lookin at that and came up with this ..but it dosent work..
i can use the click feature becase its a button not a mouse button :)

c::
Send, {c down}
KeyWait, c, D ; wait here until next c (=toggle)
Send, {c up}
Return

when the key is pressed nothing happens no letter appears and in game in fact it crouches but dosent toggle..


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2006, 7:42 am 
Offline

Joined: March 11th, 2006, 12:44 pm
Posts: 341
Location: Munich, Germany
i guess your problem is, that c is sent only once. one c down.
but you maybe want to have repeated sends of c ?

Code:
c::
  SetTimer, send_c , 20
  keyWait, c , D
  SetTimer, send_c, off
return

send_c:
  Send, {c}
return


this sends repeated c keys each 20mseconds

you can also try to remap the capslock, which is normally sticky.
i dont know if this works.

Code:
capslock::c


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2006, 7:50 am 
Offline

Joined: October 20th, 2006, 6:57 am
Posts: 33
humm..nope htat dosent work either..
the goal im trying to accomplish is simply that the c button toggles
on and off
ie: up and down
like i push c and the button stays down so i can crouch
until i push it again so that i can come back up from crouching..
right now its one fluic motion horrible...lol


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2006, 7:57 am 
Offline

Joined: March 11th, 2006, 12:44 pm
Posts: 341
Location: Munich, Germany
i dont have more ideas, perhaps you should get a little rock and put it on the key. that would be fair cheating in the game ;)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2006, 8:01 am 
Offline

Joined: October 20th, 2006, 6:57 am
Posts: 33
lmao..the mean thing is..it did work at one point in fact but the space bar was messed up...i would push space and it would then toggle crouch..way messed up i dont know how that happend it was trippy..made me so mad because iwas useing the new version i reverted back becase it does not work right for me the program crashes


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2006, 10:18 am 
Offline

Joined: March 24th, 2006, 4:15 pm
Posts: 20
Hmmn not sure why it isn't working for you know, I had setup a crouch toggle method for BF2 and it still works in BF2142, initially I was using the toggle on/off method but I decided the default Crouch operation became handy in BF2 as well. So instead my method acts normal when I press and hold 'Ctrl' but if I double tap within a specified time window a loop is run to press and hold Ctrl, simply press and release Ctrl again to break out of Crouch. Maybe you could adapt it to your purposes. I've already posted this some time back in the main BF2 thread ...

Quote:
~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: October 20th, 2006, 4:57 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Two things to try: add $ to the hotkey name, so the hotkey won't be triggered with the sent "c", and KeyWait until the "c" key is released (not until it is pressed again).
Code:
$c::
   Send {c down}
   KeyWait c
   Send {c up}
Return
You could also experiment with SendPlay, SendInput instead of SendEvent (Send).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2006, 9:51 pm 
Offline

Joined: September 3rd, 2006, 5:34 am
Posts: 601
Location: Iowa, U.S.
Also laszlo, add a GetKeyState in the hotkey. No BF2 macros work without it as I have come to learn.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2006, 12:38 am 
Offline

Joined: October 20th, 2006, 6:57 am
Posts: 33
thanks guys ill do some testing here on all that will let ya know what i come up with..


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2006, 12:50 am 
Offline

Joined: October 20th, 2006, 6:57 am
Posts: 33
Code:
~c up:: ;use c "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, {c down} ; Initiate 'Crouch'
If IsKeyPressed("c") ; Check if 'LCtrl' pressed. If pressed & released, Break loop.
Send, {c 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
}


this is what i came up with works like a charm dubble tap c and u can crouch press c again and your back on ur feet praize lanser awsome ty
i only have one question how do i change it tomiddle mouse button its mbutton but im pretty sure send wont work also its gota be Click Mbutton something lol i got a diffrent function to map to that..also im maping the scroll up and down function on the mouse in game to look forward and back for anyone who wants ta know :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2006, 4:07 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
This looks functionally equivalent. Does not it work?
Code:
~c up::
   If (a_tickCount-lasttime < 400) ; If c was pressed within 400ms: initiate Crouch
   {
       Send {c down}               ; Initiate 'Crouch'
       If GetKeyState("c")         ; Check if c pressed
          Send {c up}              ; Release "Crouch'
   }
   lasttime:=a_tickCount
Return
If it does, you could further simplify it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2006, 11:53 am 
Offline

Joined: March 11th, 2006, 12:44 pm
Posts: 341
Location: Munich, Germany
@lazlo: i guess the difference is that in the one example with "loop" the key is sent repeatedly, and in your example only one c-down is sent.
if you have a windows programm this might work as the key is repeated automatically. but perhaps the game does not recognize the c-down up but only checks for c-pressed ?

this means my example with settimer would also work if you change settimer ,...,20 to settimer, ...,0

but this looks like an endless-loop... (100%cpu ?!)

there is a difference in keywait and GetKeyState

a) Keywait. waits at this line in the programm until the "watched" key is pressed. like a "pause" (or sleep until key is pressed)
b) getkeystate only looks into the keybuffer if the key is pressed "now" (realtime) and returns immediately.

so they are not "functionally the same" ;)

but using this loop thing is an endless loop and "bad" in my opinion (when there is no "sleep" in between as the cpu is constantly watching the keystate 100%cpu, which is nonsense.

my example would then look like this
Code:
$c::   ; prevent recursion with $
  SetTimer, send_c_key , 0
  keyWait, c , D ; currently is D, so waits for "next" D = toggle
  SetTimer, send_c_key, off
return

send_c_key:
  Send, {c}
return


actually settimer,...,0 means settimer,...,10 on window 2k or xp

Quote:
From SetTimer-Documentation:
Currently, timers cannot run much more often than every 10ms on Windows XP/2000/NT and about 55ms on Windows 9x. Specifying a Period less than this will usually result in an actual interval of 10 or 55 (but this policy could change in future versions so shouldn't be relied upon).



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2006, 3:38 pm 
Offline

Joined: September 3rd, 2006, 5:34 am
Posts: 601
Location: Iowa, U.S.
Code:
$c::

GetKeyState, state, C, P
if State = D
break

Send, {Alt down}
return

$c up::

GetKeyState, state, C, P
if State = U
break

Send, {Alt up}
return


Not sure if this works.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 33 posts ]  Go to page 1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Maestr0, migz99, tomoe_uehara and 62 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