这些模块依赖于 MicroPython 端实现的 machine.USBD() 对象,该对象是 TinyUSB 的“应用程序”设备类驱动程序的瘦 C 包装器。该工作位于 micropython/micropython#9497 中,目前仅在 rp2 端口上受支持。
代码: 全选
import time
import device, hid
ud = device.get()
m = hid.MouseInterface()
ud.add_interface(m)
ud.reenumerate()
time.sleep(3) # TODO: provide a way to find out at runtime if an interface is active
print('Moving...')
m.move_by(-100, 0)
time.sleep(0.25)
print('Clicking...')
m.click_right(True)
time.sleep(0.25)
m.click_right(False)