From 37584ebf7f977ca47860cca25a69fe64069ced37 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 21 Jan 2017 01:29:51 +0700 Subject: [PATCH] add key sequence function --- .../Bluefruit52Lib/src/services/BLEHid.cpp | 21 +++++++++++++++++++ .../Bluefruit52Lib/src/services/BLEHid.h | 1 + 2 files changed, 22 insertions(+) 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); }; //--------------------------------------------------------------------+