TinyUSB with Seeeduino XIAO

I’m trying to use Adafruit_TinyUSB with a Seeeduino XIAO to emulate mouse buttons. I can get a mouse button press to work, but if the mouseMove(0,x,y) instruction is executed, the mouse button is no longer pressed, making it impossible to drag. I’m not good enough in C to go into the libraries and figure out how to fix this. Can someone help?

Can’t you instead of a mouseMove and mouseButtonPress/mouseButtonRelease functions use the more general mouseReport() method that has all arguments you need (x,y position and pressed button info)?

However also based on the implementation you can see here, there’s another possibility

due to the mouse button caching you can do a single mouseReport() once to press the button, that will save the mouse button state, then use moveMouse(),and then another mouseReport() to release it. moveMouse will use the cached _mouse_button state saved from an earlier call to mouseReport(). You can also wrap it in functions that you use instead of pressing and releasing.

Example (untested)

//assuming usb_hid is a globally available variable for the USB HID mouse device
bool mouseButtonPressAndRemember(uint8_t report_id, uint8_t buttons) { 
   return usb_hid.mouseReport(report_id, buttons, 0, 0, 0, 0);

bool mouseButtonReleaseAndRemember(uint8_t report_id)  {
   return usb_hid.mouseReport(report_id, 0, 0, 0, 0, 0);
//mouseMove as normal

//use mouseButtonPressAndRemember and mouseButtonReleaseAndRemember in function.

1 Like

Wow! Thanks for your thoughtful reply. I’m going to have to study this for a while to understand how to use it.

Thank you again! I was able to understand how to use what you showed me, and it does exactly what I needed.

1 Like