how to implement mouse click in nrf desktop

Hello,

I am looking at nrf desktop sample in ncs 2.4.2. I am using nrf52840dk and relevant files. My goal is to make composite usb/bt device mouse and keyboard work.

I see in src/hw_interface there is

-buttons_sim.c, which shows how to do keyboard keypresses.

-motion_buttons.c, which simulates mouse movement using buttons

1. Are my interpretations of these files correct?

2. Is there an example implementation where a mouse click is shown?

If not, could you give a small example for how to do this? The example I'm looking for should be end in APP_EVENT_SUBMIT()

An explanatory explanation of how to do it could also suffice.

Eg. for mouse movement, it is very simple

void mouse_movement_send(int8_t x, int8_t y)
{
    struct motion_event *event = new_motion_event();
    event->dx = x;
    event->dy = y;
    APP_EVENT_SUBMIT(event);
}

Thank you!
  • It's working.

    I ended up adding more items to the hid_keymap in hid_keymap_def_keyboard.h.

    A critical piece is a different first index in KEY_ID to allow it to coexist with the keyboard definitions.

        //Other keyboard definitions above...
        { KEY_ID(0x00, 0x1B), 0x001B, REPORT_ID_KEYBOARD_KEYS }, /* X */
        { KEY_ID(0x00, 0x1C), 0x001C, REPORT_ID_KEYBOARD_KEYS }, /* Y */
        { KEY_ID(0x00, 0x1D), 0x001D, REPORT_ID_KEYBOARD_KEYS }, /* Z */
    
    //New mouse definitions. Note new major index
        { KEY_ID(0x01, 0x00), 0x01, REPORT_ID_MOUSE }, /* Left Mouse Button */
        { KEY_ID(0x01, 0x01), 0x02, REPORT_ID_MOUSE }, /* Right Mouse Button */
        { KEY_ID(0x01, 0x02), 0x03, REPORT_ID_MOUSE }, /* Middle Mouse Button */
    
    You need to redefine the KEY_IDs in a place that's visible or accessible to the sender. There's definitely a cleaner way to do this, I'm just happy it's working for now.
    const static uint16_t mouse_click_keys[] = {
        KEY_ID(0x01, 0x00), /* LMB */
        KEY_ID(0x01, 0x01), /* RMB */
        KEY_ID(0x01, 0x02), /* MMB */
    };
    My send function:
            struct button_event *event = new_button_event();
            event->key_id = mouse_click_keys[MOUSE_BTN_IDX_LEFT];
            event->pressed = down;
            APP_EVENT_SUBMIT(event);
  • Hello man can you help me with move moving.I saw one person on YouTube transmitting native mouse move events through CrazyRadio PA. I'm a newbie and tried to find in the doc how to do this, but didn't understand anything. Maybe you can answer me here or in a telegram, here is my nickname dag2134

Related