Skip to main content
IHadz.1
Associate
July 12, 2022
Question

USB HID right click button

  • July 12, 2022
  • 2 replies
  • 1441 views

Hello,

I am designing board with stm32f723 with 2 USB. On one side i have mouse attached to STM on other side STM attached to PC. When i transfer report to PC x, y and left click button works fine but i cant make right click.

Bellow is the struct of Mouse HID:

typedef struct _HID_MOUSE_Info

{

 uint8_t       x;

 uint8_t       y;

 uint8_t       buttons[3];

}

HID_MOUSE_Info_TypeDef;

Bellow is the Send Report:

#define CLICK_REPORT_SIZE 5

uint8_t click_report[CLICK_REPORT_SIZE] = {0};

HID_MOUSE_Info_TypeDef *Mouse_Info;

uint8_t leftclick = Mouse_Info -> buttons[0];

uint8_t rightclick = Mouse_Info -> buttons[1];

click_report[0] = leftclick; // works

click_report[1] = Mouse_Info -> x; // works

click_report[2] = Mouse_Info -> y; // works

click_report[3] = rightclick; // does not working

click_report[4] = Mouse_Info -> buttons[2]; // does not working

USBD_HID_SendReport(&hUsbDeviceFS,(uint8_t*)click_report,sizeof(CLICK_REPORT_SIZE));

This topic has been closed for replies.

2 replies

Pavel A.
Super User
July 12, 2022

ST provides some examples for host HID, please look at these, you will see that the right mouse button works. The catch is that these examples work only with "classic" mouse report format.

Many mice in the wild have different report formats, so one has to read and parse the HID descriptor.

For example - 12 or 16 bits of X,Y, and have scroll.

This is not trivial and not covered in the ST examples. Try to find "classic" compatible mice for your project.

IHadz.1
IHadz.1Author
Associate
July 13, 2022

Thank you out of the question is there function to detect disconnection of the device.

USB_DevDisconnect() is not working couse it detect the mouse is of when it is in IDLE.