AutoHotkey Community

It is currently May 26th, 2012, 5:23 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 28 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: January 10th, 2005, 5:21 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Thanks. I found the bug: the following line (and another like it for the second key) has been added:

if Key1ToHoldDown <> %Key1ToHoldDownPrev% ; Key #1 needs adjusting
...

You can get the corrected version in my edited post above this one. Hopefully it will work as well as the 4-direction one now.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 19th, 2005, 6:49 pm 
Works perfectly!

thanks for you help


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2005, 12:10 am 
Offline

Joined: May 18th, 2004, 7:25 am
Posts: 7
Ugh. Well I somewhat understand the code you've written Chris. The directional button works so thanks for that. I'm trying to expand the code to get buttons 1 - 8 and one of the two joysticks on my Recoil gamepad to work with the game Area-51. Here's a link to the pad that I'm have
http://www.gemini-usa.com/a5/modelDetai ... =GemGaming
So I'm starting with button 6 or rather joy6 but I can't get it to work. What am I doing wrong here. Can someone help me here.

Code:
#Persistent
SetTimer, WatchPOV, 5
return

; The "GetKeyState" checks if a keyboard key or mouse/joystick button
; is down or up. Also retrieves joystick status.
; GetKeyState, OutputVar, KeyName [, Mode]
WatchPOV:
GetKeyState, POV, JoyPOV  ; Get position of the POV control.
Key1ToHoldDownPrev = %Key1ToHoldDown%
Key2ToHoldDownPrev = %Key2ToHoldDown%
; Each "Prev" variable now holds the key that was down before (if any).

GetKeyState, PadButton6, Joy6 ; Get postion of button 6 on the gamepad
PadKey6ToHoldDownPrev = %PadKey6ToHoldDown%

; Some joysticks might have a smooth/continous POV rather than one in fixed increments.
; To support them all, check for ranges:
if POV < 0   ; No angle to report
{
   Key1ToHoldDown =
   Key2ToHoldDown =
}
else if POV > 33750                 ; 337.5 to 360 degrees: Forward
{    ; move forward
   Key1ToHoldDown = w
   Key2ToHoldDown =
}
else if POV between 0 and 2250      ; 0 to 22.5 degrees: Forward
{    ; move forward
   Key1ToHoldDown = w
   Key2ToHoldDown =
}
else if POV between 2251 and 6750   ; Up+Right
{    ; move forward & strafe right
   Key1ToHoldDown = w
   Key2ToHoldDown = d
}
else if POV between 6751 and 11250  ; Right
{    ; strafe right
   Key1ToHoldDown =
   Key2ToHoldDown = d
}
else if POV between 11251 and 15750 ; Down+Right
{    ; lean right
   Key1ToHoldDown = e
   Key2ToHoldDown =
}
else if POV between 15751 and 20250 ; Down
{    ; move backwards
   Key1ToHoldDown = s
   Key2ToHoldDown =
}
else if POV between 20251 and 24750 ; Down+Left
{    ; lean left
   Key1ToHoldDown = q
   Key2ToHoldDown =
}
else if POV between 24751 and 29250 ; Left
{    ; strafe left
   Key1ToHoldDown = a
   Key2ToHoldDown =
}
else if POV between 29251 and 33750 ; Up+Left
{    ; move forward & strafe left
   Key1ToHoldDown = w
   Key2ToHoldDown = a
}

if (PadButton6 = D or PadButton6 = U)
   {   
   ; assign left mouse button to variable PadKey6ToHoldDown
   ; fire primary weapon
   PadKey6ToHoldDown = LButton
   ; MsgBox, 0, , The button status is %PadButton6%,
    }
   
SetKeyDelay -1  ; Avoid delays between keystrokes.

if Key1ToHoldDown <> %Key1ToHoldDownPrev%  ; Key #1 needs adjusting.
{
   if Key1ToHoldDownPrev <>   ; There is a previous key to release.
      Send, {%Key1ToHoldDownPrev% up}  ; Release it.
   if Key1ToHoldDown <>   ; There is a key to press down.
      Send, {%Key1ToHoldDown% down}  ; Press it down.
}
if Key2ToHoldDown <> %Key2ToHoldDownPrev%  ; Key #2 needs adjusting.
{
   if Key2ToHoldDownPrev <>   ; There is a previous key to release.
      Send, {%Key2ToHoldDownPrev% up}  ; Release it.
   if Key2ToHoldDown <>   ; There is a key to press down.
      Send, {%Key2ToHoldDown% down}  ; Press it down.
}
if PadKey6ToHoldDown <> %PadKey6ToHoldDownPrev% ; compare current button status to previous status
   {
   if PadKey6ToHoldDownPrev <>
      ; Send, {%PadKey6ToHoldDownPrev% up}   ; Release left mouse button
      Send, Left mouse button up
   if PadKey6ToHoldDown <>
      ; Send, (%PadKey6ToHoldDown% down)   ; press & hold the left mouse button down
      Send, Left mouse button down
   }
return

_________________
Must nothing. There's always another way.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2005, 9:55 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Here's one problem. Because it's an expression, the following line should have quotes around both D and U:
Quote:
if (PadButton6 = D or PadButton6 = U)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 10th, 2005, 6:02 pm 
can anyone translate these POV actions into joystick positions?


Report this post
Top
  
Reply with quote  
PostPosted: June 19th, 2006, 5:39 pm 
So Im using the below script and I want %keytoholddown% to behave like a keyboard key, that is first pushing it once and then repeat until i release the pov? how is this possible? now it only press the key once.

Code:
#Persistent
SetTimer, WatchPOV, 5
return

WatchPOV:
GetKeyState, POV, JoyPOV  ; Get position of the POV control.
KeyToHoldDownPrev = %KeyToHoldDown%  ; Prev now holds the key that was down before (if any).

; Some joysticks might have a smooth/continous POV rather than one in fixed increments.
; To support them all, use a range:
if POV < 0   ; No angle to report
   KeyToHoldDown =
else if POV > 31500                 ; 315 to 360 degrees: Forward
   KeyToHoldDown = Up
else if POV between 0 and 4500      ; 0 to 45 degrees: Forward
   KeyToHoldDown = Up
else if POV between 4501 and 13500  ; 45 to 135 degrees: Right
   KeyToHoldDown = Right
else if POV between 13501 and 22500 ; 135 to 225 degrees: Down
   KeyToHoldDown = Down
else                                ; 225 to 315 degrees: Left
   KeyToHoldDown = Left

if KeyToHoldDown = %KeyToHoldDownPrev%  ; The correct key is already down
   return  ; Do nothing.

; Otherwise, release the previous key and press down the new key:
SetKeyDelay -1  ; Avoid delays between keystrokes.
if KeyToHoldDownPrev <>   ; There is a previous key to release.
   Send, {%KeyToHoldDownPrev% up}  ; Release it.
if KeyToHoldDown <>   ; There is a key to press down.
   Send, {%KeyToHoldDown% down}  ; Press it down.
return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 20th, 2006, 3:36 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
This topic might help: http://www.autohotkey.com/forum/viewtopic.php?t=4623


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 20th, 2006, 1:34 pm 
Im very new to programming, I have tried to combine the two scritps, maybe you could give me some hints. I know that the script below is not working but I dont know the problem.

Code:
#Persistent
SetTimer, WatchPOV, 5
return

WatchPOV:
GetKeyState, POV, JoyPOV  ; Get position of the POV control.
KeyToHoldDownPrev = %KeyToHoldDown%  ; Prev now holds the key that was down before (if any).

; Some joysticks might have a smooth/continous POV rather than one in fixed increments.
; To support them all, use a range:
if POV < 0   ; No angle to report
   KeyToHoldDown =
else if POV > 31500                 ; 315 to 360 degrees: Forward
   KeyToHoldDown = Up
else if POV between 0 and 4500      ; 0 to 45 degrees: Forward
   KeyToHoldDown = Up
else if POV between 4501 and 13500  ; 45 to 135 degrees: Right
   KeyToHoldDown = Right
else if POV between 13501 and 22500 ; 135 to 225 degrees: Down
   KeyToHoldDown = Down
else                                ; 225 to 315 degrees: Left
   KeyToHoldDown = Left

if KeyToHoldDown = %KeyToHoldDownPrev%  ; The correct key is already down
   return  ; Do nothing.

; Otherwise, release the previous key and press down the new key:
SetKeyDelay -1  ; Avoid delays between keystrokes.
if KeyToHoldDownPrev <>   ; There is a previous key to release.
   Send, {%KeyToHoldDownPrev% up}  ; Release it.
if KeyToHoldDown <>   ; There is a key to press down.
   Send, {%KeyToHoldDown% down}  ; Press it down.
KeyWait %KeyToHoldDown%, T0.5  ; Adjust 0.5 to be the seconds prior to repeat.
if not ErrorLevel  ; The joystick button was released prior to the delay period.
{
   Send {%KeyToHoldDown% up}  ; No auto-repeat.
   return
}
; Since above didn't return, KeyWait timed out, meaning user is holding down the button.
Loop
{
   Send {%KeyToHoldDown% down}  ; Auto-repeat consists of consecutive down-events (no up events).
   Sleep 30  ; Adjust 30 to be the milliseconds between repeats.
   if not GetKeyState(%KeyToHoldDown%)  ; Joystick button has been released.
   {
      Send {%KeyToHoldDown% up}
      return
   }
   ; Otherwise, user is still holding down the button, so continue looping.
}


return



Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 21st, 2006, 3:12 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
I added the following new info to the joystick remapping page:

Auto-repeating a keystroke: Both examples above can be modified to send the key repeatedly rather than merely holding it down (that is, they can mimic physically holding down a key on the keyboard). To do this, replace the following line:
Code:
return  ; Do nothing.

WITH:
Code:
{
   if KeyToHoldDown
      Send, {%KeyToHoldDown% down}  ; Auto-repeat the keystroke.
   return
}

See the joystick remapping page for full details.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2006, 6:38 pm 
there is an way to make the POV start to work as the arrows, but stop working as an POV?(cuz im tring to play "Devil May Cry3" and this game have the worst controls ever) or make a keyboard send an joystick comand, cause i need to map all the comands, and i need 15 buttons to do it, my joystick is an playstatio-like joystick(i dont know the name) and it has only 12 + the 4 POV(it does not support the "pause" button, so i have only 15 buttons to fill 15 commands) and everytime i use the POV as the movement control(cause the POV -> Arrows scrpt) i attack, or open the map, or jump, or anything that i dont want, so i was planning to make some dummy buttons to fill those commands and i wold be able to play it, but i cant (for some reason) use that "::" stuff(I.E. q::w, that make the "Q" become "W").

and unless i can remap the joystick axes i cant use the axes to move, cuz everytime i move the left axe to the right, the character moves up, and when i move the other axe to the left, the character moves down, and so...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2006, 1:25 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Guedez wrote:
there is an way to make the POV start to work as the arrows, but stop working as an POV?
Not that I know of (other than configuring the game to turn off its response to POV movement).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2006, 5:57 pm 
yeah, but that damn game dont let me do it, unless if i simulate that my joystick have 16 buttons instead of 12 T.T


Report this post
Top
  
Reply with quote  
 Post subject: joystick repeat
PostPosted: May 17th, 2007, 4:16 am 
I read through many posts, and found this one most helpful. I was also experiencing trouble having the joystick's arrow pad (hat) repeat like a keyboard arrow key when I held it down. Here is my problem, when I tap a key on the joysticks directional pad just once, it will repeat the keypress 2x no matter what. Example, in the game I am playing I want to only tap the 'left' on the directional pad to make the character face left, however it sends the 'arrow key left' twice instead of only once. Therefore instead of only turning and facing left, the character turns and takes one step. When I want to walk multiple steps I can hold the directional button and it performs flawless, however when I just want to tap the directional pad and merely send one arrow key stroke just to face in the direction instead of proceding to move, it always repeats. I hope this is clear enough but I am feeling rather stuck at this point.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: batto, BrandonHotkey, mrhobbeys, MSN [Bot], Mtes, perlsmith, rbrtryn, stanman and 60 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