printScancode[ln](...) pressScancode(...) et releaseScancode(...)

Parent Previous Next


Fonctions:

       printScancode(  unsigned int scancode )

pressScancode( unsigned int scancode )

releaseScancode(  unsigned int scancode )


Description:

       Permet l'appui ou le relâchement d'une touche de caractère directement avec le scancode,


Arguments:

       Un  scancode correspondant à la table ASCII étendu du fichier KeyboardEx.h.


Fonction associée:

setAlign(...)


Valeur de retour:

       Retourne 1 si la fonction réussie sinon renvoie 0



Exemple:

KeyboardEx.printScancode(scancode);



Code:


#include "Adafruit_TinyUSB.h"

#include "KeyboardEx.h"


// Report ID

enum

{

 RID_KEYBOARD = 1,

 // RID_MOUSE,

 RID_CONSUMER_CONTROL, // Media, volume etc ..

};


// HID report descriptor using TinyUSB's template

uint8_t const desc_hid_report[] =

{

 //TUD_HID_REPORT_DESC_KEYBOARD(),

 TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(RID_KEYBOARD) ),

 //TUD_HID_REPORT_DESC_MOUSE   ( HID_REPORT_ID(RID_MOUSE) ),

 TUD_HID_REPORT_DESC_CONSUMER( HID_REPORT_ID(RID_CONSUMER_CONTROL) )

};


Adafruit_USBD_HID usb_hid;

// --------------------------------------------------------------------------


const char texte[] = {"Article à 12€ en ce moment!"};


String chaine = {"La monnaie de la France est: € l'euro"};



void setup() {

 usb_hid.setPollInterval(2);

 usb_hid.setReportDescriptor(desc_hid_report, sizeof(desc_hid_report));

 usb_hid.setReportCallback(get_report_callback , hid_report_callback);


 usb_hid.begin();

 KeyboardEx.begin(usb_hid, RID_KEYBOARD);


 // KeyboardEx.setOS(Windows); // Si vous êtes sur Windows, permet l'utilisation des Alt Codes.

 // KeyboardEx.setDelay(5); // valeur par défaut, si problème augmenter la valeur à 10.


 // Commenter ces lignes si vous n'utilisez oas le port série

 Serial.begin(115200);

 while (!Serial) {

   ; // wait for serial port to connect. Needed for native USB

 }

 delay(6000);

}


void loop() {

 static int oneloop = 0;


 // n'aime pas le while(1)

 if (!oneloop) {

   oneloop = 1;


 // **********************************************************************************************

 //  Test de la fonction avancée -> KeyboardEx.scancode(...)

 //  Cette fonction fonctionnera seulement pour les caracères correspondant au clavier utilisé

 //  donc à la table _asciimapEx[] déclarée dans le fichier KeyboardEx.h

 // **********************************************************************************************

 KeyboardEx.println(F("***  Test de la fonction avancée -> KeyboardEx.scancode(...) ***"));


 KeyboardEx.println();

 KeyboardEx.print("Phrase: ");

 KeyboardEx.println(texte);

 KeyboardEx.println();


 for (unsigned int i = 0; i < strlen(texte); i++) {

   if (KeyboardEx.setAlign(texte, i)) {

     const char* character = KeyboardEx.getCharacter();

     unsigned int scancode = KeyboardEx.scancode();


     if (KeyboardEx.isLayout()) { // Correspond à une touche du clavier

       if (strcmp(character, "€") == 0) {

         KeyboardEx.println();

         KeyboardEx.print("Monnaie de la France: ");

         KeyboardEx.printScancodeln(scancode);

       } else {

         KeyboardEx.printScancode(scancode);

       }

     }

   } else {

     // Erreur, sortir immédiatement

     break;

   }

 }

 KeyboardEx.println();


 KeyboardEx.println();

 KeyboardEx.println();

 KeyboardEx.print("Phrase: ");

 KeyboardEx.println(chaine);

 KeyboardEx.println();


 for (unsigned int i = 0; i < chaine.length(); i++) {

   if (KeyboardEx.setAlign(chaine, i)) {

     const char* character = KeyboardEx.getCharacter();

     unsigned int scancode = KeyboardEx.scancode();


     if (KeyboardEx.isLayout()) { // Correspond à une touche du clavier

       if (strcmp(character, "€") == 0) {

         KeyboardEx.println();

         KeyboardEx.print("Monnaie de la France: ");

         KeyboardEx.printScancodeln(scancode);

       } else {

         KeyboardEx.printScancode(scancode);

       }

     }

   } else {

     // Erreur, sortir immédiatement

     break;

   }

 }


 KeyboardEx.println();


 KeyboardEx.end();

 }

}



uint16_t get_report_callback (uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen)

{

 // Mettre Null à la place de get_report_callback dans cette fonction ci- dessous déclarée plus haut

 // si vous souhaitez supprmer cette procédure

 // usb_hid.setReportCallback(get_report_callback , hid_report_callback) -> usb_hid.setReportCallback(Null , hid_report_callback);


 // not used in this example

 return 0;

}


// Output report callback for LED indicator such as Caplocks

void hid_report_callback(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize)

{

 uint8_t ledIndicator;


 // LED indicator is output report with only 1 byte length

 if ( report_type != HID_REPORT_TYPE_OUTPUT ) return;

 // KEYBOARD_LED_KANA (8) | KEYBOARD_LED_COMPOSE (3) | KEYBOARD_LED_SCROLLLOCK (4) | KEYBOARD_LED_CAPSLOCK (2) | KEYBOARD_LED_NUMLOCK (1)


 // buffer[0] si clavier seul

 // ou buffer[1] si plusieurs reports

 if (bufsize == 2) {

   ledIndicator = buffer[1];

 } else {

   ledIndicator = buffer[0];

 }

 // Allumer la led de la carte si CAPSLOCK (verrouillage des majuscule) est activé

 // La led ne s'allumera pas sur Adafruit QT py car c'est une Neopixel

 // mais sur un Seeeduino XIAO ok

 digitalWrite(LED_BUILTIN, !(ledIndicator & KEYBOARD_LED_CAPSLOCK));

}