ESP32 Mouse + Keyboard (incl. Media) at the same time

Hello,

I want to use the HID Mouse and Keyboard functionallity - incl. Media function - at the same time.

The library from T-vK support either Mouse or Keyboard - not at the same time.

Afterwards I found two similar librarys from
jakern, support of media keys, but this library has problems with the mouse - no function - reconnect?
blackketter, has solved mouse reconnect, keyboard and mouse is working, but no Media Keys

Does anybody knows a library with supports Mouse+Keyboard+Media. I'm not able to combine the functionallity of both libraries - I tried it, but I failed.

Regards, Arduino4Fun

Hi again,

now I took the library from blackketter as a base and added the lines from jakern ... in ...

bleKeyboardInstance->connectionStatus->inputMediaKeys = bleKeyboardInstance->inputMediaKeys;

BleComboKeyboard.cpp

BLECharacteristic* inputMediaKeys;

BleConnectionStatus.h

Now it seems, that it works -> Mouse + Keyboard + Media

But there is still a difference in BleConnectionStatus.cpp

blackketter

#include "BleConnectionStatus.h"

BleConnectionStatus::BleConnectionStatus(void) {
}

void BleConnectionStatus::onConnect(BLEServer* pServer)
{
  this->connected = true;
  BLE2902* desc = (BLE2902*)this->inputKeyboard->getDescriptorByUUID(BLEUUID((uint16_t)0x2902));
  desc->setNotifications(true);
  desc = (BLE2902*)this->inputMouse->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->inputMouse->getDescriptorByUUID(BLEUUID((uint16_t)0x2902));
  desc->setNotifications(false);  
}

jakern

#include "BleConnectionStatus.h"

BleConnectionStatus::BleConnectionStatus(void) {
}

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);
}

At the moment I only use the implementation of Blackketter including the two lines. I'm not sure if I still need adjustments in BleConnectionStatus.cpp for MediaKeys support.
I would be happy to receive advice on this solution or if someone sees difficulties.
Best regards, Arduino4Fun

And again,

after Media Keys not reconnected after plug off/on, now I combined the two files to

#include "BleConnectionStatus.h"

BleConnectionStatus::BleConnectionStatus(void) {
}

void BleConnectionStatus::onConnect(BLEServer* pServer)
{
  this->connected = true;

  BLE2902* desc = (BLE2902*)this->inputKeyboard->getDescriptorByUUID(BLEUUID((uint16_t)0x2902));
  desc->setNotifications(true);

  desc = (BLE2902*)this->inputMouse->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->inputMouse->getDescriptorByUUID(BLEUUID((uint16_t)0x2902));
  desc->setNotifications(false);  

  desc = (BLE2902*)this->inputMediaKeys->getDescriptorByUUID(BLEUUID((uint16_t)0x2902));
  desc->setNotifications(false);
}

Now also reconnect of Media Keys are working - hopefully no all works fine...

The function KEY_MEDIA_MUTE, KEY_MEDIA_PLAY_PAUSE, KEY_MEDIA_NEXT_TRACK are working as wanted. But when sending

Keyboard.write( KEY_MEDIA_VOLUME_UP );

and

Keyboard.write( KEY_MEDIA_VOLUME_DOWN );

lead to blocking PC. I'm not able to switch from window to window by ALT+TAB after sending this commands. It takes a while for the PC to react normally again. Strange.

Best regards, Arduino4Fun

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.