T-vK / ESP32-BLE-Keyboard

Bluetooth LE Keyboard library for the ESP32 (Arduino IDE compatible)
2.4k stars 402 forks source link

Support mouse and keyboard profile #172

Open DevDavisNunez opened 2 years ago

DevDavisNunez commented 2 years ago

Could you make a profile that acts as a keyboard and mouse combo?

ywz978020607 commented 2 years ago

If a esp32 could act as mouse and keyboard meantime, it would be more useful!

WaGi-Coding commented 1 year ago

I also look for a solution with a single BLE service that supports both the mouse and keyboard HID report descriptors, and use the same service to send and receive data for both devices. In this case, you would not need to disconnect and reconnect to switch between the mouse and keyboard.

I hope the creator can do this, i won't dive into BLE communication myself too deep ._. (aka. I am too stupid ^^)

I found this https://github.com/blackketter/ESP32-BLE-Combo but looks a bit inactive & has a annoying bug, that it works fine sending mouse and keyboard when you link the device, but when you restart the esp32, only the mouse works. Then you have to remove the device from your pc and link it again :/ //Edit: Keyboard.print/printl still works, just write seems to have that problem in his library, not sure if the error is the same with this one. But what i did is just

Keyboard.write(KEY_MEDIA_MUTE);
delay(50);
Mouse.move(10, 10);

when a button got pressed. After restarting ESP, only the Mouse.move fires. When i replace the write with eg "Keyboard.print("hello") it works fine after restarting as well

//Edit2: Okay, it's just a problem with blackketter's library, it works fine with just using BLE-Keyboard

//Edit3: So i finally found a fork which supports all, even gamepad: https://github.com/juanmcasillas/ESP32-BLE-Combo

alexz006 commented 1 year ago

//Edit3: So i finally found a fork which supports all, even gamepad: https://github.com/juanmcasillas/ESP32-BLE-Combo

Does not work on iPhone 13 Pro Max. And to make it work on Android, you need to change the line in the file BleCombo.cpp:

//pSecurity->setAuthenticationMode(ESP_LE_AUTH_REQ_SC_MITM_BOND);
pSecurity->setAuthenticationMode(ESP_LE_AUTH_BOND);
alexz006 commented 1 year ago

Keyboard and mouse https://github.com/Georgegipa/ESP32-BLE-Combo

Works on iPhone 13 Pro Max and Windows 11. To make it work on Android, you need to change a line in the file BleCombo.cpp (tested on Android 10, 12 and 13):

//pSecurity->setAuthenticationMode(ESP_LE_AUTH_REQ_SC_MITM_BOND);
pSecurity->setAuthenticationMode(ESP_LE_AUTH_BOND);
alexz006 commented 1 year ago

My fork with fixes and adding support for reading Numlock/Capslock/Scrolllock state https://github.com/alexz006/ESP32-BLE-Combo