Solved

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

Posted on 1998-04-27
3
813 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

624 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