This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Click in HID mouse example

Dear Nordic Team,

I am using HID mouse example code in my nordic dk board.

I can able implemented fallowing logic in my code to do left , right and middle button click.

static void mouse_click_send(uint8_t x, uint8_t y, uint8_t z) { uint32_t err_code; uint8_t * buffer; if (m_in_boot_mode) return;

buffer[0] = x; // Left button (bit 0) pressed
buffer[1] = y; // Scroll value (-127, 128)
buffer[2] = z; // Sideways scroll value (-127, 128)

err_code = ble_hids_inp_rep_send(&m_hids,INPUT_REP_BUTTONS_INDEX, INPUT_REP_BUTTONS_LEN, buffer);
if ((err_code != NRF_SUCCESS) &&
    (err_code != NRF_ERROR_INVALID_STATE) &&
    (err_code != BLE_ERROR_NO_TX_BUFFERS) &&
    (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
)
{
    APP_ERROR_CHECK(err_code);
}

}

mouse_click_send(1,0,0); // this is changing the screen in my android. mouse_click_send(2,0,0); // Nothing happen mouse_click_send(3,0,0); // Nothing happen

Could you tell me what this function will do exactly in android?.

I also need to do click in my android , so that i can open application.

Could you tell me what is data format i need to send?.

Kindly tell me, your help will be greatly appreciable.

Regards SamV

  • Hi Sam,

    Have you looked at this case ?

    If you send mouse_click_send(1,0,0); would it act as a click in Android ?

    I don't think Android main screen would handle right click, maybe in your app you can handle that, but I'm not 100% sure.

  • Yes , i checked that case , could you please let me know , how can i handle click in android.

    or what is data need to send for click in android.

    Or i also want to develop hid mouse application as absolute mouse ?.

    Could you please tell me how to understand the report map data and characteristic?.

  • Hi Sam, If you want to know how to handle mouse in Android you may have to look into this documentation.

    A left mouse click in Android is pretty much the same as a touch on the screen.

    Regarding HID report and how to understand, I found a good tutorial here. In that page you will find the link to the HID1_11.pdf spec defined by USB.org.

    It's also explained by the answer from Jon Helge in the case I cited above.

  • I am confused, i went through that documents but not able to understand fully.

    i just want to do click in my android by using existing ble hid mouse example.

    kindly let me know how to do?.

  • Hi SamV,

    I found one bug with the code you provide. uint8_t * buffer; is not initialized before you use it. You should assign it to an array or do malloc. If you change the code to:

    static void mouse_click_send(uint8_t x, uint8_t y, uint8_t z) 
    	{ 
    		uint32_t err_code; uint8_t buffer[3]; 
    		if (m_in_boot_mode) return; 
    
        buffer[0] = x; // Left button (bit 0) pressed
    		buffer[1] = y; // Scroll value (-127, 128)
    		buffer[2] = z; // Sideways scroll value (-127, 128)
    
    		err_code = ble_hids_inp_rep_send(&m_hids,INPUT_REP_BUTTONS_INDEX, INPUT_REP_BUTTONS_LEN, buffer);
    		if ((err_code != NRF_SUCCESS) &&
    				(err_code != NRF_ERROR_INVALID_STATE) &&
    				(err_code != BLE_ERROR_NO_TX_BUFFERS) &&
    				(err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
    			)
    		{
    				APP_ERROR_CHECK(err_code);
    		}
    }
    

    It should work.

    To make a left click you call mouse_click_send(1,0,0); don't forget to release the key press by calling: mouse_click_send(0,0,0);

Related