December 7, 201015 yr Following my post on reading the keyboard in a C gauge (Event Handler: Push and Hold ) I've found out how to read the joystick by using joyGetPositionEx().As before, I used the fuel gauge provided in the SDKs and modified it as shown: FLOAT64 FSAPI fuel_needle_cb( PELEMENT_NEEDLE pelement ){ FLOAT64 val = pelement->source_var.var_value.n; //************************ INSERTED LINES BEGIN *************************** JOYINFOEX Joystick; unsigned int ButtonsPressed; unsigned int Buttons; // ********************** INSERTED LINES END ******************************** if (val > GAUGE_MAX_FUEL) val = GAUGE_MAX_FUEL; else if (val < GAUGE_MIN_FUEL) val = GAUGE_MIN_FUEL; // ******************** INSERTED CODE BEGINS ***************************** // Read joystick Joystick.dwSize = sizeof(Joystick); Joystick.dwFlags = JOY_RETURNALL; if (joyGetPosEx(JOYSTICKID1,&Joystick) == JOYERR_NOERROR) { ButtonsPressed = Joystick.dwButtonNumber; Buttons = Joystick.dwButtons; if (ButtonsPressed != 0) val = 0.0; } // ********************* INSERTED CODE ENDS ******************************** return val;} It's also necessary to add the line #include <mmsystem.h>As before, pressing and holding any joystick button causes the displayed fuel quantity to drop to zero instantly - releasing it causes it to increase back to the actual value instantly. If the button is assigned to a Flight Simulator action, then that action also occurs. I've only bothered with reading buttons to establish the principle, although joyGetPosEx() can return the position of the joystick as well.In the snippet:ButtonsPressed (Joystick.dwButtonNumber) is the number of buttons pressed Buttons (Joystick.dwButtons) identifies which buttons are presed - bit 0 for button 1; bit 1 for button 2 etc.There is further information here: http://msdn.microsof...108(VS.85).aspx Gerry Howard
December 9, 201015 yr Hey, thanks for your post.Interestingly enough, the JOYINFOEX structure seems to contain not only button state but axes position as well. An alternative to DInput?Gotta fiddle around with it. :(
December 9, 201015 yr Author Hey, thanks for your post.Interestingly enough, the JOYINFOEX structure seems to contain not only button state but axes position as well. An alternative to DInput?Gotta fiddle around with it. :( Yes. That was the way it was done bwfore DirectX/DirectInput. As often happens, i've subsequently come across this technique in a book published in 1997! Gerry Howard
Create an account or sign in to comment