the joystick by moving the handle or control
the joystick by moving the handle or control pad in all of its directions, followed by pressing another button (see Figure 7.4). Figure 7.4. The Device Calibration Wizard determines the range of each joystick axis by asking you to move the handle or control pad in each direction. The final step is to leave the handle (control pad) alone once more and press a button. After performing these steps, you can click the Finish button to wrap up the calibration process. Although the steps to calibrating a joystick or game pad might seem kind of pointless, the idea is that your computer is analyzing the range of movement along each axis and properly determining the center point of each. Once the center point and maximum extents are determined, the joystick can then be accurately centered. Again, it’s very much like aligning a car so that it steers straight when you aren’t touching the steering wheel. I encourage you to calibrate your joystick any time it starts acting strange because it is possible for a joystick to lose calibration over a period of time as it begins to wear mechanically. Your joystick’s Properties window usually provides a test option for testing the joystick after you’ve calibrated it; this helps to make sure that the calibration worked properly. Figure 7.5 shows an example of a test window for the Microsoft SideWinder game pad. Figure 7.5. The test window for the Microsoft SideWinder game pad allows you to test out the control pad as well as the game pad’s buttons. The test window for a joystick or game pad is great because it quickly allows you to see if the device is working properly. If you get no response when testing a device, you know that something is wrong with the installation. You can also use the test window to see if a joystick or game pad is properly calibrated. Tracking Joystick Movements As you might have guessed, joysticks are a little more complicated to deal with than other input devices such as the keyboard and mouse. This primarily has to do with the fact that joysticks aren’t exactly considered standard devices, as well as the fact that there is a fair amount of variance when it comes to joystick features. The added complexity doesn’t have so much to do with handling specific joystick events as it does with determining if a joystick is connected and available for use. You also have to concern yourself with the concept of capturing a joystick, which gives your program exclusive control over the joystick. The first step in handling joystick input is checking to see if a joystick driver is installed and available on the computer system. Without the proper hardware driver in place, a physical joystick device is no good. Fortunately, Windows includes built-in drivers for most popular joysticks. However, it’s good to perform the check anyway. This is made possible by a call to a Win32 API function called joyGetNumDevs(). The joyGetNumDevs() function tells you how many joysticks are capable of being used on the computer system. Following is an example of how you might call the joyGetNumDevs() function to determine the number of joysticks available for use on the system: UINT uiNumJoysticks = joyGetNumDevs(); You now know how many joysticks can be used on the system, but that doesn’t tell you much about how many joysticks are actually present. To see if a real joystick is actually plugged in and ready to use, you call the joyGetPos() function, which provides a lot of information about a joystick. You must pass this function an ID that identifies the joystick you’re interested in; standard joystick IDs include JOYSTICKID1, JOYSTICKID2, and so on. So, to check for the presence of a single joystick, you can use code like this: JOYINFO jiInfo; if (joyGetPos(JOYSTICKID1, &jiInfo) != JOYERR_UNPLUGGED) // the joystick is plugged in and ready to go! In this code, the joyGetPos() function is called to retrieve joystick information for a single joystick in the form of a JOYINFO structure. You learn how to use the JOYINFO structure to analyze the state of the joystick in just a moment. For now, you’re simply providing it because the joyGetPos() function requires it. All you’re looking for in this code is the return value of joyGetPos(), which indicates whether the joystick is plugged in
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services