ESP32-BLE-Keyboard icon indicating copy to clipboard operation
ESP32-BLE-Keyboard copied to clipboard

How to add an Android specific action keys

Open llilakoblock opened this issue 2 years ago • 5 comments

Hi and thanks for a great library! It works flawlessly with my project. But I still cant understand logic behind key encoding. So basically, I want to add specific Android keystroke to be able to send it. Like this one https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_VOICE_ASSIST

I have read suggested answers in another issue, but they are IOS specific. Any help would be appreciated!

llilakoblock avatar Jan 26 '23 10:01 llilakoblock

Maybe this is helpful: https://www.usb.org/sites/default/files/voice_command_usage.pdf But only adding this value to the hidReportDescriptor isn't enough, I guess. I got the info above from here: https://usb.org/sites/default/files/hut1_3_0.pdf

mayaku2go avatar Jan 26 '23 11:01 mayaku2go

Here is a complete tutorial about custom HID report descriptors: https://eleccelerator.com/tutorial-about-usb-hid-report-descriptors/

mayaku2go avatar Jan 26 '23 11:01 mayaku2go

Here is a complete tutorial about custom HID report descriptors: https://eleccelerator.com/tutorial-about-usb-hid-report-descriptors/

Thanks! Will try to dive in it 👍

llilakoblock avatar Jan 26 '23 13:01 llilakoblock

So, for anyone wondering how to make it done.

For key event KEYCODE_VOICE_ASSIST to be understood right by Android, we must implement Headphone HID device, it in Consumer section with four functions, according to Android ref and USB docs: https://source.android.com/docs/core/interaction/accessories/headset/usb-headset-spec https://usb.org/sites/default/files/hut1_2.pdf

Extending HID report in BleKeyboard.cpp:

image

Extending MediaKeyReport in BleKeyboard.h:

image

And registering our new Report ID in begin() func:

image

Issue may be closed.

llilakoblock avatar Jan 27 '23 17:01 llilakoblock

Hello, This library is really great, it works well for texting and taking a photo (with KEY MEDIA VOLUME_UP) It would be great to add the keycodes to open the Android camera app and other possibilities as shown in this link : https://elementalx.org/button-mapper/android-key-codes/ I have read the recommended documents and I tried to understand how HID descriptors work but I admit that it's too complicated for me... 8-(( Is there anyone who could help me write the missing code ? I would be happy to do all the tests.

roberto1963 avatar Feb 24 '23 16:02 roberto1963