HELP WITH ARDUINO LEONARDO KEYBOARD :(

Hello everyone,

I'm in need of the community's help for setting up my Arduino Leonardo keyboard. First off, my keyboard/arduino is going to simulate the guitar controller(which I've made one myself) for the "Giutar Hero" game, more precisely "Clone Hero" (I'm playing on pc). For every key on the guitar I've managed to bind it to a letter on the keyboard, for example, the green button is the letter "y", the red button in the letter "x" and so on. My code is pretty simple(which I'm going to upload) but the problem is I can't press two keys simultaneously, for example if I try to press "yx" together(because the game has double key presses), the arduino reads only one letter...
How can I insert in my code the possibility when i press two keys together, they both turn on. :frowning:

#include <Keyboard.h>

void setup() {
  pinMode(2,INPUT_PULLUP);
  pinMode(3,INPUT_PULLUP);
  pinMode(4,INPUT_PULLUP); 
  pinMode(5,INPUT_PULLUP);
  pinMode(6,INPUT_PULLUP);
  pinMode(7,INPUT_PULLUP);
  pinMode(8,INPUT_PULLUP);

 Serial.begin(9600);    //begin seral comms for debugging
}

void loop() {
  Keyboard.begin();
  if (digitalRead(2) == 0) //if button 2 is pushed
   {
Keyboard.write('z');
}
   else if (digitalRead(3) == 0) //if button 3 is pushed
{
  Keyboard.write('x');
}
   else if (digitalRead(4) == 0)
{
  Keyboard.write('c');  
}
   else if (digitalRead(5) == 0)
{
  Keyboard.write('v'); 
}
   else if (digitalRead(6) == 0)
{   
   Keyboard.write('b');
} 
   else if (digitalRead(7) == 0)
{
   Keyboard.write('n');
}        
   else if (digitalRead(8) == 0)
{
   Keyboard.write('m');    
}
   else if ((digitalRead(2) == 0) && (digitalRead(3) == 0))
{
  Keyboard.write('y');
  Keyboard.write('x');
}     
   Keyboard.end();
}

Computer keyboard isn't supposed to have 2 keys pressed at once. That gets called "an error".

An Uno can read 6 at once if they're all on the same port (pin map shows the pins by port). You only need 7 buttons, they can all be read and combined as one 7-bit value in less than a microsecond. Put caps across the buttons to hardware debounce them and that value will be good the instant it's read.

Kick up your serial rate! 9600 baud is 960 chars per second (start bit, 8 data bits, stop bit = 10 bits per char), more than a millisecond between "notes". Use at least 115200 (set Serial Monitor to match) if possible.

A switch...case structure will run faster than that if-else ladder.

That link is to the Arduino main site language reference page on switch...case. Go up one level and bookmark that if you didn't know it's there. There is enough material on the main site alone to fill a manual and the Arduino Playground has enough for a second volume.