1

I'm trying to make a macro keyboard, where I can press a single button and it will open programs for me.

I'm trying to type this, for example: "c:\windows"

but it gets typed out like this: cÑ}windows

I tried using double backslash (\), but it still isn't working

#include <HID-Project.h>
#include <HID-Settings.h>

#include <Keypad.h>

#define L_ALT KEY_LEFT_ALT
#define TAB KEY_TAB
#define WIN KEY_LEFT_GUI
#define ENTER KEY_RETURN

const byte FILAS = 4;
const byte COLUMNAS = 4;
//define the cymbols on the buttons of the keypads
char Keys[FILAS][COLUMNAS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte pinesFilas[FILAS] = {9, 8, 7, 6};
byte pinesColumnas[COLUMNAS] = {5, 4, 3, 2};

char TECLA;

Keypad teclado = Keypad( makeKeymap(Keys), pinesFilas, pinesColumnas, FILAS, COLUMNAS);

void setup() {
  Serial.begin(9600);
  Keyboard.begin();
}

void loop() {
  TECLA = teclado.getKey();

  if (TECLA) {

    switch (TECLA) {
      case '1':
        Serial.print("Tecla 1 presionada");
        break;
      case '2':
        Serial.print("Tecla 2 presionada");
        break;
      case '3':
        Serial.print("Tecla 3 presionada");
        break;
      case 'A':
        Serial.print("Tecla A presionada");

        
        break;
      case '4':
        Serial.print("Tecla 4 presionada");

        Keyboard.press(WIN);
        Keyboard.write('r');
        Keyboard.release(WIN);
        delay(100);
        Keyboard.print("C:\Program Files (x86)\AIMP\AIMP.exe");   //Here's the problem
        //Keyboard.write(ENTER);
        break;
      case '5':
        Serial.print("Tecla 5 presionada");
        break;
      case '6':
        Serial.print("Tecla 6 presionada");
        break;
      case 'B':
        Serial.print("Tecla B presionada");
        break;
      case '7':
        Serial.print("Tecla 7 presionada");
        break;
      case '8':
        Serial.print("Tecla 8 presionada");
        break;
      case '9':
        Serial.print("Tecla 9 presionada");
        break;
      case 'C':
        Serial.print("Tecla C presionada");
        break;
      case '*':
        Serial.print("Tecla * presionada");
        break;
      case '0':
        Serial.print("Tecla 0 presionada");
        break;
      case '#':
        Serial.print("Tecla # presionada");
        break;
      case 'D':
        Serial.print("Tecla D presionada");
        break;
    }
  }
}
1
  • 2
    That sounds like you have a different keyboard layout set up at your PC than the Keyboard library has. I think it uses the standard US layout.
    – chrisl
    Mar 10, 2022 at 21:07

1 Answer 1

3

You have to keep in mind that the Arduino doesn't send characters to the computer. Instead, it simulates key presses, and the computer has to translate those into characters, according to some keyboard layout. By default, the Keyboard library assumes the US keyboard layout.

If you are using another layout, you have to tell the library when initializing it. E.g.

Keyboard.begin(KeyboardLayout_es_ES);

would work with a Spanish keyboard layout.

C.f. the documentation of Keyboard.begin().

If you are using an unsupported layout, you may need to write your own layout file and add it to the library. You may then contribute it upstream so that it becomes part of future versions of the Keyboard library.

Alternatively, you could switch your layout to US in your OS.

PS: The Keyboard library only supports international keyboard layouts since version 1.0.3, released on 2021-11-04.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.