Is it possiable to use hid_mouse and hid_keyboard same time?

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
shaoziyang
Posts: 303
Joined: Sun Apr 17, 2016 1:55 pm

Is it possiable to use hid_mouse and hid_keyboard same time?

Post by shaoziyang » Mon Mar 02, 2020 3:29 am

Pyboard can work as a use mouse

Code: Select all

pyb.usb_mode('VCP+HID', hid = pyb.hid_mouse)
or a use keyboard

Code: Select all

pyb.usb_mode('VCP+HID', hid = pyb.hid_keyboard)
But is it possiable to use hid_mouse and hid_keyboard same time?

User avatar
jimmo
Posts: 1440
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Is it possiable to use hid_mouse and hid_keyboard same time?

Post by jimmo » Mon Mar 02, 2020 10:28 am

shaoziyang wrote:
Mon Mar 02, 2020 3:29 am
But is it possiable to use hid_mouse and hid_keyboard same time?
Not currently, but this could be supported with some code changes.

Note that my understanding of how this works is that one HID interface does one function (rather than a function per endpoint on the interface). i.e. my USB keyboard that I'm typing this on has a trackpoint mouse built in, and it shows up as a single device with two HID interfaces.

So it would require adding something like pyb.usb_mode('VCP+HID+HID') (similar to how e.g. 'VCP+VCP+MSC' is supported on some board).

shaoziyang
Posts: 303
Joined: Sun Apr 17, 2016 1:55 pm

Re: Is it possiable to use hid_mouse and hid_keyboard same time?

Post by shaoziyang » Mon Mar 02, 2020 12:25 pm

In circuitpython, it use usb_hid.devices[0] for keyboard, and usb_hid.devices[1] for mouse.

User avatar
jimmo
Posts: 1440
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Is it possiable to use hid_mouse and hid_keyboard same time?

Post by jimmo » Mon Mar 02, 2020 1:06 pm

CircuitPython do USB very differently (right down to a different USB stack).

shaoziyang
Posts: 303
Joined: Sun Apr 17, 2016 1:55 pm

Re: Is it possiable to use hid_mouse and hid_keyboard same time?

Post by shaoziyang » Tue Mar 03, 2020 1:38 am

Hope micropython can provide a method use hid_mouse and hid_keyboard together.

danhalbert
Posts: 8
Joined: Mon Jan 16, 2017 3:58 am

Re: Is it possiable to use hid_mouse and hid_keyboard same time?

Post by danhalbert » Thu Mar 05, 2020 2:06 pm

CircuitPython uses a composite HID device descriptor that provides mouse, keyboard, "consumer control" (media keys like volume up/down), and a gamepad. Optionally there is a Microsoft XAC-compatible gamepad, a digitizer, "system control" (power buttons), and raw HID.

The advantage of the composite descriptor is that all the these HID descriptors only use up one USB endpoint pair. The disadvantage is that the keyboard and mouse are not "boot devices", and sodon't work with many BIOS'es.

Currently these descriptors are generated at compile-time, and can be selected via compile-time flags. We have long-term plans to allow generating the HID descriptors (and choosing USB devices in general via descriptors) at run-time in boot.py, but we're not there yet.

Further technical discussion is probably best done in a GitHub issue.

Post Reply