Problème bibliothèque Keyboard

Bonjour,
J'ai besoin de simuler un clavier avec un Arduino Micro branché en USB sur un PC. J'utilise la bibliothèque Keyboard version 1.0.6.
Les touches à simuler sont haut, bas, gauche, droite, + et -. Tout fonctionne sauf la simulation de la touche - qui donne ')'.
Le problème est présent sur un PC Windows et sur un Raspberry Pi avec Linux.
Ci-dessous le code :

#include <Keyboard.h>

void setup() {
  // Déclare les broches utilisées pour les boutons
  pinMode(2, INPUT_PULLUP); // Bouton Haut
  pinMode(3, INPUT_PULLUP); // Bouton Bas
  pinMode(4, INPUT_PULLUP); // Bouton Gauche
  pinMode(5, INPUT_PULLUP); // Bouton Droite
  pinMode(6, INPUT_PULLUP); // Bouton Plus
  pinMode(7, INPUT_PULLUP); // Bouton Moins

  // Initialise la communication avec le clavier
  Keyboard.begin();
}

void loop() {
  // Vérifie si les boutons sont enfoncés
  if (digitalRead(2) == LOW) {
    Keyboard.write(KEY_UP_ARROW); // Simule la touche Haut
    delay(100);
  }
  if (digitalRead(3) == LOW) {
    Keyboard.write(KEY_DOWN_ARROW); // Simule la touche Bas
    delay(100);
  }
  if (digitalRead(4) == LOW) {
    Keyboard.write(KEY_LEFT_ARROW); // Simule la touche Gauche
    delay(100);
  }
  if (digitalRead(5) == LOW) {
    Keyboard.write(KEY_RIGHT_ARROW); // Simule la touche Droite
    delay(100);
  }
  if (digitalRead(6) == LOW) {
    Keyboard.write('+'); // Simule la touche Plus
    delay(100);
  }
  if (digitalRead(7) == LOW) {
    Keyboard.write('-'); // Simule la touche Moins
    delay(100);
  }
}

merci à ce qui prendrons un moment pour peu- êtres trouver une solution.
bonne fin de journée.

C'est peut-être un problème de langue. Par défaut, il est configuré en clavier US :
void begin(const uint8_t *layout = KeyboardLayout_en_US);

Essaye avec :
Keyboard.begin(KeyboardLayout_fr_FR);

merci mais Il semble que la bibliothèque Keyboard.h ne dispose pas d'une méthode set_layout pour définir la disposition du clavier.

j'ai trouver cette solution qui fonctionne mais à mon avis ce n'est pas idéal :

#include <Keyboard.h>

void setup() {
  // Déclare les broches utilisées pour les boutons
  pinMode(2, INPUT_PULLUP); // Bouton Haut
  pinMode(3, INPUT_PULLUP); // Bouton Bas
  pinMode(4, INPUT_PULLUP); // Bouton Gauche
  pinMode(5, INPUT_PULLUP); // Bouton Droite
  pinMode(6, INPUT_PULLUP); // Bouton Plus
  pinMode(7, INPUT_PULLUP); // Bouton Moins

  // Initialise la communication avec le clavier
  Keyboard.begin();
}

void loop() {
  // Vérifie si les boutons sont enfoncés
  if (digitalRead(2) == LOW) {
    Keyboard.write(KEY_UP_ARROW); // Simule la touche Haut
    delay(100);
  }
  if (digitalRead(3) == LOW) {
    Keyboard.write(KEY_DOWN_ARROW); // Simule la touche Bas
    delay(100);
  }
  if (digitalRead(4) == LOW) {
    Keyboard.write(KEY_LEFT_ARROW); // Simule la touche Gauche
    delay(100);
  }
  if (digitalRead(5) == LOW) {
    Keyboard.write(KEY_RIGHT_ARROW); // Simule la touche Droite
    delay(100);
  }
  if (digitalRead(6) == LOW) {
    Keyboard.write('+'); // Simule la touche Plus
    delay(100);
  }
  if (digitalRead(7) == LOW) {
    // Simule la touche Moins (touche '9' avec la touche Shift)
    //Keyboard.press(KEY_LEFT_SHIFT);
    Keyboard.write('6');
   // Keyboard.release(KEY_LEFT_SHIFT);
    delay(100);
  }
}

Pas besoin de set_layout, c'est l'argument normal de la méthode begin : les layouts sont définis dans le fichier .h

// Supported keyboard layouts
extern const uint8_t KeyboardLayout_de_DE[];
extern const uint8_t KeyboardLayout_en_US[];
extern const uint8_t KeyboardLayout_es_ES[];
extern const uint8_t KeyboardLayout_fr_FR[];
extern const uint8_t KeyboardLayout_it_IT[];
extern const uint8_t KeyboardLayout_pt_PT[];
extern const uint8_t KeyboardLayout_sv_SE[];
extern const uint8_t KeyboardLayout_da_DK[];
extern const uint8_t KeyboardLayout_hu_HU[];

Le layout FR est ici :

La touche '-' renvoie 0x23, tu peux tenter :
Keyboard.write(0x23);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.