button array and button box not working as needed.

I’m putting together a Sim system for Prepar3d and for some reason the code works fine in the joystick setting through Windows 10, but the button box is not working in the simulator properly. This is the code I’m using. The axis inputs work fine in and out of the simulator. The buttons/switches don’t. I have to cycle my switches on then off to get an input in the Sim. I will attach a link to YouTube at the end of the post for visual purposes. Any help is appreciated.

#include <Keypad.h>
#include “Joystick.h”

#define NUMBUTTONS 18
#define NUMROWS 3
#define NUMCOLS 6

byte buttons[NUMROWS][NUMCOLS] {
{0, 1, 2, 3, 4, 5},
{6, 7, 8, 9, 10, 11},
{12, 13, 14, 15, 16, 17}

byte rowPins[NUMROWS] {2,4,7};
byte colPins[NUMCOLS] {3, 5, 6, 9, 10, 11};

Keypad buttbx {Keypad(makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS)};

// 2 Buttons, No hats, X and Y axis, no Z axis, Rx, Ry, Rz, Rudder, Throttle, Brake, or Steering
true, true, false, false, false, false, false, true, false, false, false);

const bool initAutoSendState = true;

void setup() {


pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(3, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);

Joystick.setXAxisRange(0, 1023);
Joystick.setYAxisRange(0, 1023);
Joystick.setThrottleRange(0, 1023);

void loop(){

// X-Axis
int xAxis = analogRead(A0);
// Serial.println(xAxis);

// Y-Axis
int yAxis = analogRead(A1);
// Serial.println(yAxis);

// Throttle
int Throttle = analogRead(A2);
// Serial.println(Throttle);


#define LIST

void CheckAllButtons(void){
for(int i=0; i<LIST_MAX; i++)

  • {*
    _ switch(buttbx.key*.kstate){_
    case PRESSED:_
    _ Joystick.setButton(buttbx.key.kchar, 1);
    case HOLD:
    case RELEASED:
    case IDLE:
    Joystick.setButton(buttbx.key.kchar, 0);

    youtube video link: https://youtu.be/KUYHTIxNvlA_

Please Read this before posting a programming question ...

I think your problem is in how buttons/switches are mapped to functions in Prepar3D. When mapping, you have to say if it is a "momentary switch" (typically a push button) or a "latching switch" (typically an on/off switch)
(I don't know how they are named in P3D....)

Your description of the problem, matches configuring a "latching switch" as "momentary".

A "momentary switch" will toggle a function each time it is pressed and released, which is the same as turning a latching switch on and off.