You can poll the joystick for position and button information. For example, an application might poll the joystick to get baseline position values; the Joystick Control Panel applet uses this technique when calibrating the joystick. The joyGetPos function allows you to poll the joystick for position and button information. It has the following syntax:
WORD joyGetPos(wID, lpJoyInfo)
The wID parameter identifies the joystick. The lpJoyInfo parameter is a far pointer to a JOYINFO structure that is filled by the function.
Note:
Calling joyGetPos while joystick input is captured can prevent the joystick services from accurately reporting joystick events to the capture window.
The JOYINFO structure has the following form:
typedef struct joyinfo_tag {
WORD wXpos;
WORD wYpos;
WORD wZpos;
WORD wButtons;
} JOYINFO;
The wXpos, wYpos, and wZpos fields specify the current x-, y-, and z-position of the joystick.
The wButtons field specifies the button states. This can be any combination of the JOY_BUTTON bit flags. For example, the following expression evaluates to TRUE if button 1 is pressed:
joyinfo.wButtons & JOY_BUTTON1
See “Processing Joystick Messages,” earlier in this chapter, for an explanation of the JOY_BUTTON flags.