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

Parents
  • 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.

  • 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);

Reply
  • 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);

Children
No Data
Related