Probleme conversion qwerty/azerty

J'ai écrit mon code sur ARDUINO et il s'exécute normalement mais j'ai rencontré un problème : par exemple lorsque j'écris keyboard.print("m") il écrit une virgule
Je voudrais savoir comment régler ce problème : y a t-il une methode de conversion qwerty/azerty ou autre .
Merci

12 réponses

  • Votes
  • Date
  • Date décroissante
  1. Contributeur
    Bonjour,

    Le problème vient de la bibliothèque Keyboard qui se base sur un clavier américain.
    Il faut donc redéfinir la variable _asciimap dans le fichier HID.c et mettre :
    const uint8_t _asciimap[128] =
    {
    	0x00,             /* NUL */
    	0x00,             /* SOH */
    	0x00,             /* STX */
    	0x00,             /* ETX */
    	0x00,             /* EOT */
    	0x00,             /* ENQ */
    	0x00,             /* ACK */
    	0x00,             /* BEL */
    	0x2a,			/* BS	Backspace */
    	0x2b,			/* TAB	Tab */
    	0x28,			/* LF	Enter */
    	0x00,             /* VT */
    	0x00,             /* FF */
    	0x00,             /* CR */ 
    	0x00,             /* SO */
    	0x00,             /* SI */
    	0x00,             /* DEL */
    	0x00,             /* DC1 */
    	0x00,             /* DC2 */
    	0x00,             /* DC3 */
    	0x00,             /* DC4 */
    	0x00,             /* NAK */
    	0x00,             /* SYN */
    	0x00,             /* ETB */
    	0x00,             /* CAN */
    	0x00,             /* EM  */
    	0x00,             /* SUB */
    	0x00,             /* ESC */
    	0x00,             /* FS  */
    	0x00,             /* GS  */
    	0x00,             /* RS  */
    	0x00,             /* US  */
     
    	0x2c,		   /*  ' ' */
    	0x38,	   /* !  */
    	0x20,    /* " */
    	0x20,    /* # :TODO */
    	0x30,    /* $ */
    	0x34|SHIFT,    /* % */
    	0x1E,    /* &  */
    	0x21,          /* ' */
    	0x22,    /* ( */
    	0x2d,    /* ) */
            0x31,    /* * : done */
    	0x2b|SHIFT,    /* + */
    	0x10,          /* ,  */
    	0x23,          /* - */
    	0x36|SHIFT,    /* . */
    	0x37|SHIFT,    /* / */
    	0x27|SHIFT,    /* 0 */
    	0x1e|SHIFT,    /* 1 */
    	0x1f|SHIFT,    /* 2 */
    	0x20|SHIFT,    /* 3 */
    	0x21|SHIFT,    /* 4 */
    	0x22|SHIFT,    /* 5 */
    	0x23|SHIFT,    /* 6 */
    	0x24|SHIFT,    /* 7 */
    	0x25|SHIFT,    /* 8 */
    	0x26|SHIFT,    /* 9 */
    	0x37,          /* : */
    	0x36,          /* ; */
    	0x64,      /* < Done */
    	0x2e,          /* = */
    	0x64|SHIFT,      /* > Done */
    	0x10|SHIFT,      /* ? 0x38 -> 0x10 OK */
    	0x1f,      /* @ TODO */
    	0x14|SHIFT,      /* A */
    	0x05|SHIFT,      /* B */
    	0x06|SHIFT,      /* C */
    	0x07|SHIFT,      /* D */
    	0x08|SHIFT,      /* E */
    	0x09|SHIFT,      /* F */
    	0x0a|SHIFT,      /* G */
    	0x0b|SHIFT,      /* H */
    	0x0c|SHIFT,      /* I */
    	0x0d|SHIFT,      /* J */
    	0x0e|SHIFT,      /* K */
    	0x0f|SHIFT,      /* L */
    	0x33|SHIFT,      /* M */
    	0x11|SHIFT,      /* N */
    	0x12|SHIFT,      /* O */
    	0x13|SHIFT,      /* P */
    	0x04|SHIFT,      /* Q */
    	0x15|SHIFT,      /* R */
    	0x16|SHIFT,      /* S */
    	0x17|SHIFT,      /* T */
    	0x18|SHIFT,      /* U */
    	0x19|SHIFT,      /* V */
    	0x1d|SHIFT,      /* W */
    	0x1b|SHIFT,      /* X */
    	0x1c|SHIFT,      /* Y */
    	0x1a|SHIFT,      /* Z */
    	0x0c,          /* [ TODO 2F */
    	0x31,          /* bslash */
    	0x0d,          /* ] TODO 30 */
    	0x2F,    /* ^ */
    	0x25,    /* _ */
    	0x35,          /* ' TODO */
    	0x14,          /* a */
    	0x05,          /* b */
    	0x06,          /* c */
    	0x07,          /* d */
    	0x08,          /* e */
    	0x09,          /* f */
    	0x0a,          /* g */
    	0x0b,          /* h */
    	0x0c,          /* i */
    	0x0d,          /* j */
    	0x0e,          /* k */
    	0x0f,          /* l */
    	0x33,          /* m */
    	0x11,          /* n */
    	0x12,          /* o */
    	0x13,          /* p */
    	0x04,          /* q */
    	0x15,          /* r */
    	0x16,          /* s */
    	0x17,          /* t */
    	0x18,          /* u */
    	0x19,          /* v */
    	0x1d,          /* w */
    	0x1b,          /* x */
    	0x1c,          /* y */
    	0x1a,          /* z */
    	0x2f|SHIFT,    /*  */
    	0x31|SHIFT,    /* | TODO */
    	0x30|SHIFT,    /* } TODO */
    	0x35|SHIFT,    /* ~ TODO */
    	0				/* DEL */
    };
    

    Cdlt,
    1. Salut @fiddy :-)
      peut-être que je me trompe mais pour la keymap que ta fournie en ASCII, il n'est pas préférable de définir comme ceci ?
      	0x00,             /* NULL */
      	0x01,             /* SOH */
      	0x02,             /* STX */
      	0x03,             /* ETX */
      	0x04,             /* EOT */
      	0x05,             /* ENQ */
      	0x06,             /* ACK */
      	0x07,             /* BEL */
      	// ect..
      

      Vue que Arduino ce base sur les table ASCII
      à bientôt
    2. Contributeur
      Salut sambia39,
      Je pense que tu confonds le scancode avec l'ascii code...
      Les 0x01, ... que tu vois ici ne sont pas les codes ascii. Donc, non, il ne faut pas faire ainsi :-).
    3. Ok ok , autant pour moi
      +1
      à bientôt
    4. Bonsoir fiddly, j'ai changé mon HID.c avec ce que tu as envoyé mais arduino ne simule pas le "@" en azerty, comment pourrais je y remédier ?
  2. voici une partie :
    Keyboard.print("cmd"); il me donne ----> c;d
    Keyboard.print("del abc.vbs"); il me donne ----> del abc:vbs
    1. Bonsoir ,
      Peut tu nous fournir ton code sources ? pour savoir d'où viens le problème ?
      à bientôt
      1. Ok une partie nous avance en rien, il nous faut le une bonne partie de la sources pour comprendre
        Exemple
        #include <stdio.h>
        
        int main( void ){
        
        	unsigned int ret = 65;
        	printf( "%c\n", ret );
        	printf( "%c\n", ret - 32 );
        	
        	return ( 0 );
        }
        

        à bientôt
        1. J'ai cru que c'est suffisant ! voila:
          #include "usb_private.h"
          #include "usb_api.h"
          #include <stdio.h>
          #include <string.h>
          int inPin = 3;
          int ledPin = 11;
          boolean fileCreated = false;
          // Checks if the NUM is on
          bool isNumLockOn() {
          return bitRead(int(keyboard_leds), 0);
          }

          // Checks if the CAPS is on
          bool isCapsLockOn() {
          return bitRead(int(keyboard_leds), 1);
          }

          // Release the key
          void sendNull() {
          Keyboard.set_modifier(0);
          Keyboard.set_key1(0);
          Keyboard.send_now();
          }

          void PressAndRelease(int KeyCode,int KeyCount){
          int KeyCounter=0;
          for (KeyCounter=0; KeyCounter!=KeyCount; KeyCounter++){
          Keyboard.set_key1(KeyCode); // use r key
          Keyboard.send_now(); // send strokes
          Keyboard.set_key1(0);
          Keyboard.send_now(); // send strokes
          }
          }
          void CommandAtRunBar(char *SomeCommand){
          delay(80); // let buffer settle
          bool cps_state=isCapsLockOn();
          Keyboard.set_modifier(128); //Windows key
          Keyboard.set_key1(KEY_R); // use r key
          Keyboard.send_now(); // send strokes
          sendNull();
          delay(100);
          if (cps_state) { // If caps lock is ON set it OFF
          PressAndRelease(KEY_CAPS_LOCK,1); // push caps lock
          delay(80); // let buffer settle
          }
          Keyboard.print(SomeCommand);
          delay(50);
          PressAndRelease(KEY_ENTER,1); // push ENTER
          delay(50);
          if (cps_state) { // If caps lock was ON set it back to ON
          PressAndRelease(KEY_CAPS_LOCK,1); // push caps lock
          delay(80); // let buffer settle
          }
          }

          void setup(){
          pinMode(inPin, INPUT);
          pinMode(ledPin, OUTPUT);
          }

          void loop(){
          while (!usb_configuration) { // Wait for USB to be ready
          digitalWrite(ledPin, HIGH);
          delay(200);
          digitalWrite(ledPin, LOW);
          delay(200);

          }
          if (digitalRead(inPin) && !fileCreated) {
          bool initial_state=isCapsLockOn();

          // create vbscript and run it
          delay(300);
          CommandAtRunBar("cmd");
          delay(300);
          if (initial_state) { // If caps lock is ON set it OFF
          PressAndRelease(KEY_CAPS_LOCK,1); // push caps lock
          delay(50); // let buffer settle
          }

          Keyboard.print("del nes.vbs");
          PressAndRelease(KEY_ENTER,1); // push ENTER
          Keyboard.print("copy con nes.vbs");
          PressAndRelease(KEY_ENTER,1); // push ENTER
          1. en fait , le probleme reside dans les dernieres lignes : keyboard.print , il est entrain de les lire en qwerty
            1. merci , mais ou je peux trouver le fichier HID.c
              1. Contributeur
                Ben, il y a la fonction recherche sous Windows...
                Cela dépend où tu as installé ces fichiers. Peut-être un truc du genre : Program Files\arduino\hardware\arduino\cores\arduino
              2. oui je l'ai déjà trouvé merci
              3. j'ai fait comme a dit fiddy mais rien n'est changé , dois-je declarer une variable ou une bibliotheque dans mon code ?
              4. Contributeur
                As-tu bien utilisé Keyboard.begin() ?
              5. oui