cancel
Showing results for 
Search instead for 
Did you mean: 

In the official example(Ux_Device_HID_CDC_ACM), HID device as mouse ,how to send right or left key to pc?

Hhaon.1
Associate II

In the official example(Ux_Device_HID_CDC_ACM),HID devices as mouse

/* Mouse event. Length is fixed to . */
  hid_event->ux_device_class_hid_event_length = 3;
 
  /* Set X position. */
  hid_event->ux_device_class_hid_event_buffer[0] = x;
 
  /* Set Y position. */
  hid_event->ux_device_class_hid_event_buffer[1] = y;
 
  hid_event->ux_device_class_hid_event_buffer[2] = 0;
/* Send an event to the hid */
        ux_device_class_hid_event_set(hid, &hid_event);

but i want send key(right key or left key) to pc.

so i view google

0693W00000Hq8yLQAR.jpgFollow the above method,i Modified code

this is

/* Mouse event. Length is fixed to . */
  hid_event->ux_device_class_hid_event_length = 4;
 
  /* Set X position. */
  hid_event->ux_device_class_hid_event_buffer[0] = 2;
 
  /* Set Y position. */
 hid_event->ux_device_class_hid_event_buffer[1] = x;
 
  hid_event->ux_device_class_hid_event_buffer[2] = y;
 
 hid_event->ux_device_class_hid_event_buffer[3] = 0x00;
 /* Send an event to the hid */
        ux_device_class_hid_event_set(hid, &hid_event);

i tested,finded not send key to pc.

so i ask how to do send a right or left key to pc?​

1 REPLY 1
ABasi.2
Associate III

hello! 

The problem is that hid_mouse->ux_device_class_hid_report_id is setted to UX_TRUE (i don't known why).

That flag it as to be used if you have a report descriptor with more the one ID so the library attach at the front of the data array the byte hid_event->ux_device_class_hid_event_report_id 

in your case you  have a report descriptor with a unic ID (actually without an ID)

your interpretations of the buffer are correct:

hid_event->ux_device_class_hid_event_buffer[0]  ---> buttons

hid_event->ux_device_class_hid_event_buffer[1]  ---> X

hid_event->ux_device_class_hid_event_buffer[2]  ---> Y

hid_event->ux_device_class_hid_event_buffer[3]  ---> wheel

 

BUT with the flag setted to UX_TRUE the actual buffer become:

hid_event->ux_device_class_hid_event_buffer[0]  ---> hid_event->ux_device_class_hid_event_report_id (that is 0)

hid_event->ux_device_class_hid_event_buffer[1]  ---> buttons

hid_event->ux_device_class_hid_event_buffer[2]  ---> X

hid_event->ux_device_class_hid_event_buffer[3]  ---> Y

hid_event->ux_device_class_hid_event_buffer[4]  ---> wheel

 

in the example  the buttons are always 0 

to fix that before ux_device_class_hid_event_set(hid_mouse, &hid_event);

 

make sure to: 

hid_mouse->ux_device_class_hid_report_id = UX_FALSE;

so the hid_event->ux_device_class_hid_event_buffer[0] become actually the first byte sended