Solved

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

Posted on 1998-04-27
3
795 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 108
fizzArray2 challenge 1 90
mapBully challenge 6 152
Not needed 13 119
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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