diff --git a/libraries/Bluefruit52Lib/src/services/BLEHid.cpp b/libraries/Bluefruit52Lib/src/services/BLEHid.cpp index 543bc19c..c50323e1 100644 --- a/libraries/Bluefruit52Lib/src/services/BLEHid.cpp +++ b/libraries/Bluefruit52Lib/src/services/BLEHid.cpp @@ -456,3 +456,24 @@ err_t BLEHid::keyRelease(void) return keyboardReport(&report); } + +err_t BLEHid::keySequence(const char* str, int ms) +{ + // Send each key in sequence + char ch; + while( (ch = *str++) != 0 ) + { + char lookahead = *str; + + keyPress(ch); + delay(ms); + + /* Only need to empty report if the next character is NULL or the same with + * the current one, or no need to send */ + if ( lookahead == ch || lookahead == 0 ) + { + keyRelease(); + delay(ms); + } + } +} diff --git a/libraries/Bluefruit52Lib/src/services/BLEHid.h b/libraries/Bluefruit52Lib/src/services/BLEHid.h index 17816df5..dac27a10 100644 --- a/libraries/Bluefruit52Lib/src/services/BLEHid.h +++ b/libraries/Bluefruit52Lib/src/services/BLEHid.h @@ -96,6 +96,7 @@ class BLEHid : public BLEService err_t keyboardReport(hid_keyboard_report_t* report); err_t keyPress(char ch); err_t keyRelease(void); + err_t keySequence(const char* str, int ms=5); }; //--------------------------------------------------------------------+