Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Reading joystick in C gauge

Featured Replies

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

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. :(

  • 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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.