joyGetPos Function

Declare Function joyGetPos Lib "winmm.dll" (ByVal uJoyID As Long, pji As JOYINFO) As Long

Platforms: Win 95/98

joyGetPos reads the current position and status of a joystick. This information is put into the variable passed as pji. The function returns 0 if the joystick is connected and working, or a non-zero error code if it is not.

uJoyID
The ID number of the joystick to read, starting at 0.
pji
Variable that receives the joystick's current position and status.

Example:

' Display the x, y, and z coordinates of Joystick #1, as well
' as the status of buttons 1-4 (which are the only ones this function can read).
Dim joypos As JOYINFO  ' receives current joystick status
Dim retval As Long  ' return value

retval = joyGetPos(0, joypos)  ' get the joystick status (remember Joystick #1's ID = 0)
Debug.Print "X Coordinate:"; pos.wXpos
Debug.Print "Y Coordinate:"; pos.wYpos
Debug.Print "Z Coordinate:"; pos.wZpos
If (pos.wButtons And JOY_BUTTON1) = JOY_BUTTON1 Then Debug.Print "Button 1 is depressed."
If (pos.wButtons And JOY_BUTTON2) = JOY_BUTTON2 Then Debug.Print "Button 2 is depressed."
If (pos.wButtons And JOY_BUTTON3) = JOY_BUTTON3 Then Debug.Print "Button 3 is depressed."
If (pos.wButtons And JOY_BUTTON4) = JOY_BUTTON4 Then Debug.Print "Button 4 is depressed."

Category: Joysticks

Go back to the alphabetical Function listing.
Go back to the Reference section index.


This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/j/joygetpos.html