Fonctions:
press( Keycode k )
release( Keycode k )
write( Keycode k )
Description:
Permet de presser, de relâcher ou les deux avec write, les touches du clavier autres que celles qui correspondent à des caractères imprimables
Arguments:
une constante appartenant à l'énumération Keycode, voir plus bas
Valeur de retour:
Retourne 1 si la fonction réussie sinon renvoie 0
Constantes utilisables (voir la déclaration de l'énumération Keycode dans le fichier Keyboard.h)
TINY_KEY_RETURN TINY_KEY_CAPS_LOCK TINY_KEY_ESCAPE TINY_KEY_BACKSPACE TINY_KEY_TAB TINY_KEY_SPACE TINY_KEY_PRINT_SCREEN TINY_KEY_SCROLL_LOCK TINY_KEY_PAUSE TINY_KEY_INSERT TINY_KEY_HOME TINY_KEY_DELETE TINY_KEY_END TINY_KEY_PAGE_UP TINY_KEY_PAGE_DOWN |
TINY_KEY_F1 TINY_KEY_F2 TINY_KEY_F3 TINY_KEY_F4 TINY_KEY_F5 TINY_KEY_F6 TINY_KEY_F7 TINY_KEY_F8 TINY_KEY_F9 TINY_KEY_F10 TINY_KEY_F11 TINY_KEY_F12 |
TINY_KEY_ARROW_RIGHT TINY_KEY_ARROW_LEFT_ TINY_KEY _ARROW_DOWN TINY_KEY_ARROW_UP TINY_KEY_APPLICATION TINY_KEY_CONTROL_LEFT TINY_KEY_SHIFT_LEFT TINY_KEY_ALT_LEFT TINY_KEY_GUI_LEFT TINY_KEY_CONTROL_RIGHT TINY_KEY_SHIFT_RIGHT TINY_KEY_ALT_RIGHT TINY_KEY_GUI_RIGHT |
Exemple:
KeyboardEx.write(TINY_KEY_CAPS_LOCK);
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; // -------------------------------------------------------------------------- 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; byte ret = 0; // n'aime pas le while(1) if (!oneloop) { oneloop = 1; // ************************************************************************************** // Test fonction -> KeyboardEx.press(Keycode) release(Keycode)write(Keycode) // ************************************************************************************** KeyboardEx.println(F("*** Test fonction -> KeyboardEx.press(Keycode) release(Keycode)write(Keycode) ***")); KeyboardEx.println("arduino"); KeyboardEx.write(TINY_KEY_CAPS_LOCK); KeyboardEx.println("arduino"); KeyboardEx.write(TINY_KEY_CAPS_LOCK); delay(2000); KeyboardEx.press(TINY_KEY_F1); KeyboardEx.release(TINY_KEY_F1); 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)); } |