I'm not sure if anyone has asked this before, but I have a dual analogue controler (4 axis) that also has a d-pad seperate. I was wanting to map the second analogue stick and the d-pad to keyboard presses so I can use them in games that don't support 4 axis. Is there a way for me to do this, as I am aware that joystick axis, and joystick POV(d-pad) don't get sent as key presses. Thanls
Joystick to Keyboard Mapping
Started by
Parabol
, Sep 04 2005 07:51 AM
2 replies to this topic
#1
-
Posted 04 September 2005 - 07:51 AM
Don't worry, I managed to combine Chris' POV to key script, and a modified version of a joystic axis to button script he put up. It makes it posible to use the right analogue stick and the POV hat to trigger keys. This is good in games that only support one axis. Thanks chris. btw, here's the code, I noticed other people are after the same thing.
This version maps the POV hat to the Numpad arrows, and the Right analogue too the following.
Up = NumpadMult (*)
Down = NumpadDiv (/)
Left = NumpadSub (-)
Right = NumpadAdd(+)
This version maps the POV hat to the Numpad arrows, and the Right analogue too the following.
Up = NumpadMult (*)
Down = NumpadDiv (/)
Left = NumpadSub (-)
Right = NumpadAdd(+)
#Persistent SetTimer, WatchPOV, 5 ;SetTimer, WatchZAxis, 50 return 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). ; 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 { Key1ToHoldDown = NumpadUp Key2ToHoldDown = } else if POV between 0 and 2250 ; 0 to 22.5 degrees: Forward { Key1ToHoldDown = NumpadUp Key2ToHoldDown = } else if POV between 2251 and 6750 ; Up+Right { Key1ToHoldDown = NumpadUp Key2ToHoldDown = NumpadRight } else if POV between 6751 and 11250 ; Right { Key1ToHoldDown = Key2ToHoldDown = NumpadRight } else if POV between 11251 and 15750 ; Down+Right { Key1ToHoldDown = NumpadDown Key2ToHoldDown = NumpadRight } else if POV between 15751 and 20250 ; Down { Key1ToHoldDown = NumpadDown Key2ToHoldDown = } else if POV between 20251 and 24750 ; Down+Left { Key1ToHoldDown = NumpadDown Key2ToHoldDown = NumpadLeft } else if POV between 24751 and 29250 ; Left { Key1ToHoldDown = Key2ToHoldDown = NumpadLeft } else if POV between 29251 and 33750 ; Up+Left { Key1ToHoldDown = NumpadUp Key2ToHoldDown = NumpadLeft } 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. } GetKeyState, ZAxis, JoyZ GetKeyState, RAxis, JoyR GetKeyState, NumpadDiv, NumpadDiv GetKeyState, NumpadMult, NumpadMult GetKeyState, NumpadAdd, NumpadAdd GetKeyState, NumpadSub, NumpadSub if ZAxis > 80 ;Z is down { if NumpadDiv = U Send {NumpadDiv down} if NumpadMult = D Send {NumpadMult up} } else ; Z is not down. { if ZAxis < 20 ;Z is up { if NumpadMult = U Send {NumpadMult down} if NumpadDiv = D Send {NumpadDiv up} } else ;Z axis is Centred { if NumpadDiv = D Send {NumpadDiv up} if NumpadMult = D Send {NumpadMult up} } } if RAxis > 80 ;R is right { if NumpadAdd = U Send {NumpadAdd down} if NumpadSub = D Send {NumpadSub up} } else ; R is not right. { if RAxis < 20 ;R is left { if NumpadSub = U Send {NumpadSub down} if NumpadAdd = D Send {NumpadAdd up} } else ;R axis is Centred { if NumpadAdd = D Send {NumpadAdd up} if NumpadSub = D Send {NumpadSub up} } } return WatchZAxis:
#2
-
Posted 04 September 2005 - 08:27 AM