Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Media keys #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions BleComboKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -502,4 +503,3 @@ size_t BleComboKeyboard::write(const uint8_t *buffer, size_t size) {
}
return n;
}

7 changes: 7 additions & 0 deletions BleConnectionStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ 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)
{
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);

}
1 change: 1 addition & 0 deletions BleConnectionStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class BleConnectionStatus : public BLEServerCallbacks
void onDisconnect(BLEServer* pServer);
BLECharacteristic* inputKeyboard;
BLECharacteristic* outputKeyboard;
BLECharacteristic* inputMediaKeys;
BLECharacteristic* inputMouse;
};

Expand Down
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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);
Expand All @@ -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

Expand All @@ -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!
12 changes: 6 additions & 6 deletions library.properties
Original file line number Diff line number Diff line change
@@ -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