Buttonbox leonardo keyboard

Hello.

I'm question, how made sketch to Arduiono IDE , that when you press button , adruino read it as pressing a key R on my keyboard PC ??

I have now
void setup() {
pinMode(2, INPUT_PULLUP);
Keyboard.begin();
}

void loop() {
if (digitalRead(2) == HIGH)
Keyboard.press('R');
else
Keyboard.releaseAll();
}

But key R repeats itself RRRRRR.... without pressing

add that I have a connection arduino / button - wire pin 2 / wire GDN

INPUT_PULLUP as its name implies pulls the input HIGH when the button is not pressed.
So
  if (digitalRead(2) == HIGH) will be true until you press the button. Try  if (digitalRead(2) == LOW) instead

that is how it should look like sketch ?

Change INPUT_PULLUP ?

Change INPUT_PULLUP ?

No. That is keeping the input pin at a known HIGH state when the button is not pressed which is what you want to avoid stray voltages affecting the input.

Changeif (digitalRead(2) == HIGH)toif (digitalRead(2) == LOW)
Note that I am assuming that one of the connections to the button is connected to Arduino pin 2 and the other one is connected to GND. Is that how it is wired ?

I have button (second on image ) http://cooking-hacks.com/wp/wp-content/uploads/2012/10/Pulsador_panel_arduino.png
And i have connect first wire to pin 2 and also secod wire to ground.

Have you changed your code as I suggested ?

work, thank you very :))

yet, one question , how added new shortcuts to sketch ?

I have now
void setup() {
pinMode(2, INPUT_PULLUP);
Keyboard.begin();
}

void loop() {
if (digitalRead(2) == LOW)
Keyboard.press('R');
else
Keyboard.releaseAll();
}

between which the lines ? ex. shortcut "P" ??

Under what circumstances should the Arduino press the 'P'?

It should be pretty obvious what you need to change.

Ok , buttonbox works, but when you press repeats a few letters ex. BBBB ( one short push button ) , he dont make one letter , one push, if you can apply on delay ?

Stay away from using delay(). What you need to do is to send a letter when a button changes from not pressed to pressed rather than when the button is pressed as you are doing at present.

To do this you save the previous state of the button and if it has become pressed since the last time you checked you act on it. Look at the StateChangeDetection example in the IDE to see how to do it.

Another factor is that switch contacts bounce and do not open and close cleanly so can produce multiple on/off states even with what seems to be one button press. The IDE and the Web have examples of debouncing switches.