Issues with Arduino micro Pro Keyboard

Hello Community,

Can you help me?

I use a Arduino mirco pro to emulate a keyboard for gaming.

i write a simple code with an if-condition to check if the Pin is High. and also i use a pull down consister, that the Pin is LOW.

and if i push a button, the pin should be HIGH.

But, when ich start the Micro with a USB Cable the arduino answer with 1000' letters, but i dont know why.

i checked the volt after pushing the button and there are 4,7 V. so i think it is okay. and wenn ich dont push the button i have 0V cause of the consister.

Thank you, for your help.

@begoek, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with your project.

Please post your code (use the </> button to apply code tags). A schematic (reasonably sized photo of hand drawn is fine).

the code will come later, thanks :slight_smile:

<
int pinbutton = 0;
#include <Keyboard.h>

void setup ( )
{
pinmode (6, INPUT);
Keyboard.begin();
}

void loop ()
{
pinbutton = digitalRead(6);

if (pinbutton == HIGH)
{
Keyboard.press ('a');
delay(1000);
Keyboard.releaseAll();
}

}

Pins 0 and 1 are used by Serial1 so it is usually best to get in the habit of picking pins starting with 2 and only using 0 and 1 when desperate. :slight_smile:

You are holding the 'a' key down for a full second. I think you are seeing your keyboard auto-repeat.

Try Keyboard.write('a'); instead. That does a Keyboard.press('a'); and Keyboard.release('a');

1 Like

What do you mean using pins with 2?

I think that John was slightly confused because pinbutton contained the word pin; pinbutton is not the button pin but a variable where the state is stored. For pins, a lot of use use pin (e.g. buttonPin) in the variable name, for the reading of that pin we often use state (e.g. buttonState) in the name.

You should not use magic numbers (like 6 in your case); if you ever decide to move the button to another pin, you have to change it in two locations (or even more). This would be a better version (in my opinion)

const byte buttonPin = 6;

#include <Keyboard.h>

void setup ( )
{
  pinmode (buttonPin, INPUT);
  Keyboard.begin();
}

void loop ()
{
  int buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH)
  {
    Keyboard.press ('a');
    delay(1000);
    Keyboard.releaseAll();
  }
}

Code tags are applied with the circled button below
image

1 Like

Absolutely correct. Sorry. My mistake. Ignore that.

1 Like

Maybe you can help me with another issue. now i start the game.

i go to the Game and want to set the Keyboard. in the Settings i can set the 'a' , but when i run the game. nothing happend.

i also test it with a online keyboard tester.

what i do wrong?

Did you use Keyboard.write()? Some games have problems with very short key presses. Try:

    Keyboard.press ('a');
    delay(10);
    Keyboard.release('a');

It's a slightly longer press. Shouldn't be long enough to start auto-repeat.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.