My code isn't working, can someone please help

I am new to Arduino and don't know how to code in it well, when I press button12 it doesn't press ALT+\ . Can someone please help

#include <Keyboard.h>
int Key1 = 2;
int Key2 = 3;
int Key3 = 4;
int Key4 = 5;
int Key5 = 6;
int Key6 = 7;
int Key7 = 8;
int Key8 = 9;
int Key9 = 10;
int Key10 = 11;
int Key11 = 12;
int Key12 = 13;

void setup()
{
pinMode(Key3, INPUT);
digitalWrite(Key3, HIGH);
pinMode(Key12, INPUT);
digitalWrite(Key12, HIGH);
Keyboard.begin();
}

void loop()
{
if (digitalRead(Key3) == 0)
{
Keyboard.print("/");
delay(300);
Keyboard.print("l");
Keyboard.press(KEY_RETURN);
Keyboard.releaseAll();
delay(300);
}
else if (digitalRead(Key12) == 0)
{
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(''');
Keyboard.releaseAll();
delay(300);
}

}


yes, i did copy the basics of of a website but altered them

We need to know
What sort of Arduino you have?
How is it wired to your keypad?
What is the output connected to?

Have you tried replacing KEY_LEFT_ALT with some simple key like "Q", that you can easily verify on the PC side?

pro micro/leonardo 1 wire connecting all switches to ground

yes

You want me to guess the result?

With no input pullup resistors? You're not enabling INPUT_PULLUP in your sketch.

They have a hybrid now?

no, I bought a pro micro but to get it to work I have to set the board to Leonardo

I have 1 wire connecting 1 pin of all switches to ground and the other pin of all switches connecting to a different pin on the board

oh, I guess i wasn't very clear, the code uploads with no errors, and when I press switch 4 it works but when I press switch 12 it doesn't output anything

See reply #7

I'm sorry, I am new to Arduino I don't know what you mean but i don't have any resistors in it no

Change all your INPUT to INPUT_PULLUP in the pinMode() calls...
Delete the digitalWrite() calls that immediately follow them. That is an obsolete way of enabling INPUT_PULLUP and probably won't work on a 23U4 processor.

Like:

pinMode(Key3, INPUT_PULLUP);
pinMode(Key12, INPUT_PULLUP);

If that doesn't work, double check your wiring.

What character is that supposed to be?

Note: You should use the modern:
pinMode(Key3, INPUT_PULLUP);
instead of the archaic:

  pinMode(Key3, INPUT);
  digitalWrite(Key3, HIGH);

You can bypass your hardware circuit on pin 12 and test it by grounding one end of a wire and touching the other end to pin 12.

Edit - sorry, pin 11. Man that is confusing.

Oh, that was a backslash, don't know why it's not there. Ok I changed it but it doesn't fix it

It isn't anything circuit wise, I made sure they were all connected and wired properly, it didn't work with any of the switches, the first if statement does work though

How many times?

multiple, it was working with this other code that I was using before that only allowed me to bind then to function keys


#define BUTTON_KEY1 KEY_F13
#define BUTTON_KEY2 KEY_F14
#define BUTTON_KEY3 KEY_F15
#define BUTTON_KEY4 KEY_F16
#define BUTTON_KEY5 KEY_F17
#define BUTTON_KEY6 KEY_F18
#define BUTTON_KEY7 KEY_F19
#define BUTTON_KEY8 KEY_F20
#define BUTTON_KEY9 KEY_F24
#define BUTTON_KEY10 KEY_F23
#define BUTTON_KEY11 KEY_F22
#define BUTTON_KEY12 KEY_F21

#define BUTTON_PIN1 2
#define BUTTON_PIN2 3
#define BUTTON_PIN3 4
#define BUTTON_PIN4 5
#define BUTTON_PIN5 6
#define BUTTON_PIN6 7
#define BUTTON_PIN7 8
#define BUTTON_PIN8 9
#define BUTTON_PIN9 10
#define BUTTON_PIN10 16
#define BUTTON_PIN11 14
#define BUTTON_PIN12 15
// ---------------------------------
 
#include "Keyboard.h"

class button {
  public:
  const char key;
  const uint8_t pin;
 
  button(uint8_t k, uint8_t p) : key(k), pin(p){}
 
  void press(boolean state){
    if(state == pressed || (millis() - lastPressed  <= debounceTime)){
      return; // Nothing to see here, folks
    }
 
    lastPressed = millis();
 
    state ? Keyboard.press(key) : Keyboard.release(key);    
    pressed = state;
  }
 
  void update(){
    press(!digitalRead(pin));
  }
 
  private:
  const unsigned long debounceTime = 30;
  unsigned long lastPressed = 0;
  boolean pressed = 0;
} ;
 

button buttons[] = {
  {BUTTON_KEY1, BUTTON_PIN1},
  {BUTTON_KEY2, BUTTON_PIN2},
  {BUTTON_KEY3, BUTTON_PIN3},
  {BUTTON_KEY4, BUTTON_PIN4},
  {BUTTON_KEY5, BUTTON_PIN5},
  {BUTTON_KEY6, BUTTON_PIN6},
  {BUTTON_KEY7, BUTTON_PIN7},
  {BUTTON_KEY8, BUTTON_PIN8},
  {BUTTON_KEY9, BUTTON_PIN9},
  {BUTTON_KEY10, BUTTON_PIN10},
  {BUTTON_KEY11, BUTTON_PIN11},
  {BUTTON_KEY12, BUTTON_PIN12},
  
};
 
const uint8_t NumButtons = sizeof(buttons) / sizeof(button);
const uint8_t ledPin = 17;
 
void setup() { 

  pinMode(1, INPUT_PULLUP);
  if(!digitalRead(1)){
    failsafe();
  }
 
  // Set LEDs Off. Active low.
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
  TXLED0;
 
  for(int i = 0; i < NumButtons; i++){
    pinMode(buttons[i].pin, INPUT_PULLUP);
  }
}
 
void loop() {
  for(int i = 0; i < NumButtons; i++){
    buttons[i].update();
  }
}
 
void failsafe(){
  for(;;){}
}