Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

keyboard to joystick


  • Please log in to reply
27 replies to this topic
Gasto
  • Members
  • 7 posts
  • Last active: Jan 08 2005 09:52 PM
  • Joined: 17 Dec 2004
I asked earlier about how to do the joystick respond with certain keyboard keys, and specially make the POV act like the arrow keys in the keyboard.

Can you pleas give me an example script?

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
It would be nice to know if this works since I don't have a POV control here to test with:
#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