Solved

How to deal with extra Joystick buttons except 4 basic buttons?

Posted on 1998-04-27
3
766 Views
Last Modified: 2013-11-19
Hi! I know both MM_JOY1BUTTONDOWN and MM_JOY1BUTTONUP windows messages are able to handle Joystick 4 basic buttons. Because my Joystick totally has 8 buttons. I do not know if I need to use MM_JOY1MOVE to handle the 4 extra Joystick buttons? Could I use MM_JOY1BUTTONDOWN AND MM_JOY1BUTTONUP to deal with that directly? If the answer is Yes, How? If using MM_JOY1MOVE is the only way to solve my problem, could you tell me how to do it? Please respond me ASAP.Thanks a lot!
0
Comment
Question by:jennyhou
  • 2
3 Comments
 

Author Comment

by:jennyhou
ID: 1302673
Edited text of question
0
 

Accepted Solution

by:
santoroa earned 50 total points
ID: 1302674
In DirectInput lingo, the term "joystick" also encompasses game pads, flight yokes, pedal systems, and similar
devices. I'll use the term here with a similar range of meaning.

You can read the joystick either through Windows messages or by polling. In the first method, a window
"captures" the joystick with joySetCapture so that the window is notified whenever the joystick is moved or
a button is pressed. This makes it possible to turn the stick into a pointing device like the mouse: you can
move a pointer on the screen every time the angle of the stick is altered. Moby Dick, however, is concerned
with the position of the joystick on each pass through the game loop rather than with the stick's actual
movements, so you want to use joyGetPosEx to do your own polling rather than monitoring the message
queue.

Another reason not to use joySetCapture is that joystick messages are limited to three axes of movement
(e.g. left-right, forward-back, and throttle) and four buttons. This obviously won't do for a modern input
device like the Microsoft Sidewinder™ 3D Pro, which has eight buttons, a point-of-view hat, and four axes of
movement (including a throttle slider and a twisting motion on the stick itself). For the latest joysticks and
game pads you definitely need the power of joyGetPosEx, which returns the state of up to 32 buttons, six
axes, and the POV hat, besides transparently supporting both digital and analog devices.

The API reference advises using the old joyGetPos function for joystick devices that employ no more than
three axes and four buttons. It's true that joyGetPos is a bit simpler to implement, but joyGetPosEx works
with all joysticks, and I see no reason not to use it exclusively.

To include the extended joystick services in your program, you need to link to WINMM.LIB and include
MMSYSTEM.H.

Detecting the Joystick

To detect the primary joystick, simply call joyGetPosEx with the JOYSTICKID1 argument:


JOYINFOEX joyInfoEx;

ZeroMemory(joyInfoEx, sizeof(joyInfoEx);
joyInfoEx.dwSize = sizeof(joyInfoEx);
BOOL JoyPresent = (joyGetPosEx(JOYSTICKID1, &joyInfoEx) == JOYERR_NOERROR);

The function returns an error (non-zero) if the joystick is not properly installed in Windows or is simply
unplugged.

Note that, as with many of the other DirectX functions, you have to let joyGetPosEx know how big a
structure it has to fill--annoying, but necessary for forward compatibility. On the bright side, you don't have
to worry about the dwFlags field here, since you don't require any of the values returned in the structure.

0
 

Author Comment

by:jennyhou
ID: 1302675
Thanks a lot!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now