Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 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

13 Experts available now in Live!

Get 1:1 Help Now