
/* a partir de FSquare > “Emulating a keyboard on the Arduino - Tutorial”
  https://www.youtube.com/watch?v=DJYH2Y4-n_c
  &
  https://www.arduino.cc/en/Tutorial/ButtonMouseControl
*/

#include <Keyboard.h> //necessário com versão 1.8.0 do ardiono IDE

int btnA = 2;
int btnS = 3;
int btnD = 4;
int btnJ = 6;
int btnK = 7;
int btnL = 8;
int btnV = 11;
int btnV2 = 12;

void setup()
{
  pinMode(btnA, INPUT_PULLUP);
  pinMode(btnS, INPUT_PULLUP);
  pinMode(btnD, INPUT_PULLUP);
  pinMode(btnJ, INPUT_PULLUP);
  pinMode(btnK, INPUT_PULLUP);
  pinMode(btnL, INPUT_PULLUP);
  pinMode(btnV, INPUT_PULLUP);
  pinMode(btnV2, INPUT_PULLUP);

  Keyboard.begin();
}

void loop()
{
  if (digitalRead(btnA) == LOW)
  {
    Keyboard.press('a');
    delay(100);
    Keyboard.releaseAll();
    delay(200);
  }

  if (digitalRead(btnS) == LOW)
  {
    Keyboard.press('s');
    delay(100);
    Keyboard.releaseAll();
    delay(200);
  }

  if (digitalRead(btnD) == LOW)
  {
    Keyboard.press('d');
    delay(100);
    Keyboard.releaseAll();
    delay(200);
  }

  if (digitalRead(btnJ) == LOW)
  {
    Keyboard.press('j');
    delay(100);
    Keyboard.releaseAll();
    delay(200);
  }

  if (digitalRead(btnK) == LOW)
  {
    Keyboard.press('k');
    delay(100);
    Keyboard.releaseAll();
    delay(200);
  }

  if (digitalRead(btnL) == LOW)
  {
    Keyboard.press('l');
    delay(100);
    Keyboard.releaseAll();
    delay(200);
  }

  if (digitalRead(btnV) == LOW || digitalRead(btnV2) == LOW)
  {
    Keyboard.press('v');
    delay(100);
    Keyboard.releaseAll();
    delay(200);
  }
}
