diff --git a/BleComboKeyboard.cpp b/BleComboKeyboard.cpp index 2bc900c..55db279 100644 --- a/BleComboKeyboard.cpp +++ b/BleComboKeyboard.cpp @@ -170,10 +170,11 @@ void BleComboKeyboard::taskServer(void* pvParameter) { bleKeyboardInstance->inputMediaKeys = bleKeyboardInstance->hid->inputReport(MEDIA_KEYS_ID); bleKeyboardInstance->connectionStatus->inputKeyboard = bleKeyboardInstance->inputKeyboard; bleKeyboardInstance->connectionStatus->outputKeyboard = bleKeyboardInstance->outputKeyboard; - + bleKeyboardInstance->inputMouse = bleKeyboardInstance->hid->inputReport(MOUSE_ID); // <-- input REPORTID from report map bleKeyboardInstance->connectionStatus->inputMouse = bleKeyboardInstance->inputMouse; - + bleKeyboardInstance->connectionStatus->inputMediaKeys = bleKeyboardInstance->inputMediaKeys; + bleKeyboardInstance->outputKeyboard->setCallbacks(new KeyboardOutputCallbacks()); bleKeyboardInstance->hid->manufacturer()->setValue(bleKeyboardInstance->deviceManufacturer); @@ -502,4 +503,3 @@ size_t BleComboKeyboard::write(const uint8_t *buffer, size_t size) { } return n; } - diff --git a/BleConnectionStatus.cpp b/BleConnectionStatus.cpp index f7468f2..baf51ed 100644 --- a/BleConnectionStatus.cpp +++ b/BleConnectionStatus.cpp @@ -8,6 +8,9 @@ void BleConnectionStatus::onConnect(BLEServer* pServer) this->connected = true; BLE2902* desc = (BLE2902*)this->inputKeyboard->getDescriptorByUUID(BLEUUID((uint16_t)0x2902)); desc->setNotifications(true); + + desc = (BLE2902*)this->inputMediaKeys->getDescriptorByUUID(BLEUUID((uint16_t)0x2902)); + desc->setNotifications(true); } void BleConnectionStatus::onDisconnect(BLEServer* pServer) @@ -15,4 +18,8 @@ void BleConnectionStatus::onDisconnect(BLEServer* pServer) this->connected = false; BLE2902* desc = (BLE2902*)this->inputKeyboard->getDescriptorByUUID(BLEUUID((uint16_t)0x2902)); desc->setNotifications(false); + + desc = (BLE2902*)this->inputMediaKeys->getDescriptorByUUID(BLEUUID((uint16_t)0x2902)); + desc->setNotifications(false); + } diff --git a/BleConnectionStatus.h b/BleConnectionStatus.h index 76044d7..e5fb08d 100644 --- a/BleConnectionStatus.h +++ b/BleConnectionStatus.h @@ -16,6 +16,7 @@ class BleConnectionStatus : public BLEServerCallbacks void onDisconnect(BLEServer* pServer); BLECharacteristic* inputKeyboard; BLECharacteristic* outputKeyboard; + BLECharacteristic* inputMediaKeys; BLECharacteristic* inputMouse; }; diff --git a/README.md b/README.md index 7ca7bed..77d3777 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,23 @@ This library allows you to make the ESP32 act as a Bluetooth keyboard and mouse ## Todo +## Features + + - [x] Send key strokes + - [x] Send text + - [x] Press/release individual keys + - [x] Media keys are supported - [ ] Read Numlock/Capslock/Scrolllock state - - [ ] Add gamepad support - - [x] Auto-instantiate Keyboard, Mouse objects (like the standard Arduino libraries) - - [ ] Optimize so that only needed classes get created for BLE. + - [x] Set battery level (basically works, but doesn't show up in Android's status bar) + - [x] Compatible with Android + - [x] Compatible with Windows + - [x] Compatible with Linux + - [ ] Compatible with MacOS X (Untested) + - [ ] Compatible with iOS (Untested) ## Installation - (Make sure you can use the ESP32 with the Arduino IDE. [Instructions can be found here.](https://github.com/espressif/arduino-esp32#installation-instructions)) -- [Download the latest release of this library from the release page.](https://github.com/T-vK/ESP32-BLE-Keyboard/releases) +- [Download the latest release of this library from the release page.](https://github.com/jakern/ESP32-BLE-Combo/releases) - In the Arduino IDE go to "Sketch" -> "Include Library" -> "Add .ZIP Library..." and select the file you just downloaded. - You can now go to "File" -> "Examples" -> "ESP32 BLE Combo" and select any of the examples to get started. @@ -38,12 +47,6 @@ void loop() { Serial.println("Sending Play/Pause media key..."); Keyboard.write(KEY_MEDIA_PLAY_PAUSE); - Serial.println("Sending Ctrl+Alt+Delete..."); - Keyboard.press(KEY_LEFT_CTRL); - Keyboard.press(KEY_LEFT_ALT); - Keyboard.press(KEY_DELETE); - delay(100); - Keyboard.releaseAll(); Serial.println("Move mouse pointer up"); Mouse.move(0,-10); @@ -58,7 +61,13 @@ void loop() { Serial.println("Waiting 2 seconds..."); delay(2000); } +``` + +## API docs +The BleKeyboard interface is almost identical to the Keyboard Interface, so you can use documentation right here: +https://www.arduino.cc/reference/en/language/functions/usb/keyboard/ +Just remember that you have to use `bleKeyboard` instead of just `Keyboard` and you need these two lines at the top of your script: ``` ## Credits @@ -71,3 +80,4 @@ You might also be interested in: - [ESP32-BLE-Keyboard](https://github.com/T-vK/ESP32-BLE-Keyboard) - [ESP32-BLE-Gamepad](https://github.com/lemmingDev/ESP32-BLE-Gamepad) +Credits to [chegewara](https://github.com/chegewara) and [the authors of the USB keyboard library](https://github.com/arduino-libraries/Keyboard/) as this project is heavily based on their work! Also, credits to [duke2421](https://github.com/T-vK/ESP32-BLE-Keyboard/issues/1) who helped a lot with testing, debugging and fixing the device descriptor! diff --git a/library.properties b/library.properties index 8c36ba1..515e124 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ -name=ESP32 BLE Combo Keyboard Mouse -version=0.1.0 +name=ESP32 BLE Combo +version=0.3.0 author=T-vK -maintainer=blackketter -sentence=Bluetooth LE Combo Keyboard Mouse library for the ESP32. -paragraph=Bluetooth LE Combo Keyboard Mouse library for the ESP32. +maintainer=jakern +sentence=Bluetooth LE Combo library for the ESP32. +paragraph=Bluetooth LE Combo library for the ESP32. category=Communication -url=https://github.com/blackketter/ESP32-BLE-Combo +url=https://github.com/jakern/ESP32-BLE-Combo architectures=esp32