Pro Micro as a game device + key stroke

Hi. I'm working on a button box with an Arduino Pro Micro and I would need one of the buttons to be a key stroke.
I know you can set the board to be a game device (button box) or as a keyboard, but it can't do both things at once, right?

What happens when you try?

I think it will depend on the order you set the joystick and keyboard begin in the setup. It will identify it as the lattest

Nevermind, you actually can :slight_smile: I've figured it out.

Please post yourt sketch showing your solution for others please.

Sure. It's a super simple sketch:

#include <Joystick.h>
#include "Keyboard.h"

int boton = 2;
int tecla = 4;
const int buttonPin = 4;          // input pin for pushbutton
int previousButtonState = HIGH;   // for checking the state of a pushButton
int buttonState = 0;

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
                   JOYSTICK_TYPE_JOYSTICK, 32, 0,
                   false, false, false, false, false, false,
                   false, false, false, false, false);

void setup() {
  Keyboard.begin();
  Joystick.begin();
  pinMode(boton, INPUT_PULLUP);
  pinMode(tecla, INPUT_PULLUP);
}

void loop() {
  int buttonState = digitalRead(tecla);
  if ((buttonState != previousButtonState) && (buttonState == 0)) {
    Keyboard.print("x");
  }
  previousButtonState = buttonState;
  
  if (digitalRead(boton) == 0) {
    Joystick.setButton(0, 1);
  }
  else {
    Joystick.setButton(0, 0);
  }

}

then the wiring would be (replace the UNO with a Pro Micro):

Then Windows recognizes it as a keyboard but it's actually both things, and both the button that it's just a controller button does what is expected of it, and the button that is expected to type an "x" does so:
image