How to combine mouse and keyboad?
Opened this issue · 5 comments
I am currently experimenting with using a Raspberry Pi 4 as a PC mouse and keyboard. The mouse and keyboard examples work individually, but since they occupy the device as root, I am unable to use both at the same time.
In the case of the ESP32 sample (https://github.com/blackketter/ESP32-BLE-Combo/tree/master), there is a combined implementation, so I believe it's technically possible, and I've been trying to achieve the same.
However, after merging the report map and report for both keyboard and mouse, and adjusting the size in the text file, the device disconnects with an error a few seconds after pairing. Since I can't determine the exact details of the device error, could you provide guidance on what aspects I should focus on?
I plan to use this for direct control after screen reading with AI generation.
The problem will be in the way the report maps are combined. I will try it and report back - it may take a week.
- From mouse.c reportmap[52] change [7] from 01 to 02. This is the mouse report ID
- Merge reportmap[47] from keyboard.c and modified reportmap[52] from mouse.c into a single reportmap[99] = 05,01,09,06.......81,06,C0,C0
- Modify keyboard.txt
''''
LECHAR=Report Map SIZE=99....change size
LECHAR=Report1 SIZE=8...no change
LECHAR=Report2 SIZE=3...add from mouse.txt
''' - In keyboard.c + mouse.c combined code send_key function use reportindex to send keystrokes and reportindex+1to send mouse commands
Thanks for your support.
Actually I have already apply those (for python). driver error has occurd.
I understood the reportmap, but I have no idea for report
keyboard send 8byte and mouse send 3byte, So I confuse report = [0,0,0,0,0,0,0,0] or [0,0,0,0,0,0,0,0,0,0,0]
and
uuid = [0x2A,0x4D]
btfpy.Write_ctic(node,btfpy.Find_ctic_index(node,btfpy.UUID_2,uuid),report,0)
is correct or
uuid = [0x2A,0x4D]
btfpy.Write_ctic(node,btfpy.Find_ctic_index(node,btfpy.UUID_2,uuid),report1,0)
btfpy.Write_ctic(node,btfpy.Find_ctic_index(node,btfpy.UUID_2,uuid),report2,0)
I attach the code here
hid_combined.txt
hid_combined.py.txt
This should work - note +1 in report2 write index.
report1 = [0,0,0,0,0,0,0,0]
report2 = [0,0,0]
uuid = [0x2A,0x4D]
btfpy.Write_ctic(node,btfpy.Find_ctic_index(node,btfpy.UUID_2,uuid),report1,0)
btfpy.Write_ctic(node,btfpy.Find_ctic_index(node,btfpy.UUID_2,uuid)+1,report2,0)
Also, your report map needs a modification to set the ID of Report 2 to 02 (item [54] = 02 as below)
reportmap = [0x05,0x01,0x09,0x06,0xA1,0x01,0x85,0x01,0x05,0x07,0x19,0xE0,0x29,0xE7,0x15,0x00,\
0x25,0x01,0x75,0x01,0x95,0x08,0x81,0x02,0x95,0x01,0x75,0x08,0x81,0x01,0x95,0x06,\
0x75,0x08,0x15,0x00,0x25,0x65,0x05,0x07,0x19,0x00,0x29,0x65,0x81,0x00,0xC0,\
0x05,0x01,0x09,0x02,0xA1,0x01,0x85,0x02,0x09,0x01,0xA1,0x00,0x05,0x09,0x19,0x01,\
0x29,0x03,0x15,0x00,0x25,0x01,0x95,0x03,0x75,0x01,0x81,0x02,0x95,0x01,0x75,0x05,\
0x81,0x01,0x05,0x01,0x09,0x30,0x09,0x31,0x15,0x81,0x25,0x7F,0x75,0x08,0x95,0x02,\
0x81,0x06,0xC0,0xC0]