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

BLE hid Keyboard key press/release [Clarifications needed]

Hi,

We're working on a ble hid keyboard project, and we need some clarifications on how the keyboard keys press/release is done !

We've started with the example in the sdk v16.0.0, the example uses the keys_send() function to send a press followed by a release of that key. 

In this function there is  send_key_scan_press_release() , and i think this is the responsible for sending a press followed by a release of the key.

In our use case, we need to send just a press when the button is pushed, and a release when the button is released. in this case a hold on the button will output a successive key presses , and when released it will output just one release . this is achieved with the USB keyboard version using the app_usbd_hid_kbd_key_control() function.

 static void button_event_handler(uint8_t pin_no, uint8_t button_action)
    {
      ret_code_t err_code;
      switch(pin_no)
      {
       case BUTTON_1:
         if(button_action == APP_BUTTON_PUSH) {
            UNUSED_RETURN_VALUE(app_usbd_hid_kbd_key_control(&m_app_hid_kbd, CONFIG_KBD_KEY[0] , true));
            //NRF_LOG_INFO("button1 pressed");
         }
         else if(button_action == APP_BUTTON_RELEASE) {
            UNUSED_RETURN_VALUE(app_usbd_hid_kbd_key_control(&m_app_hid_kbd, CONFIG_KBD_KEY[0] , false));
            //NRF_LOG_INFO("button1 release");
         }
         break;
         
         }
    }     

the BLE  hid keyboard output on the host, should be as in the picture bellow (same as with the USB version) : 

USB hid keyboard log

Any help, clarifications, recommendations on how to achieve that is highly appreciated !

Best Regards,

Abdelali

Parents
  • Feel free to modify this as you see fit, also check out the api description:

    /**@brief   Function for transmitting a key scan Press & Release Notification.
     *
     * @warning This handler is an example only. You need to analyze how you wish to send the key
     *          release.
     *
     * @param[in]  p_instance     Identifies the service for which Key Notifications are requested.
     * @param[in]  p_key_pattern  Pointer to key pattern.
     * @param[in]  pattern_len    Length of key pattern. 0 < pattern_len < 7.
     * @param[in]  pattern_offset Offset applied to Key Pattern for transmission.
     * @param[out] actual_len     Provides actual length of Key Pattern transmitted, making buffering of
     *                            rest possible if needed.
     * @return     NRF_SUCCESS on success, NRF_ERROR_RESOURCES in case transmission could not be
     *             completed due to lack of transmission buffer or other error codes indicating reason
     *             for failure.
     *
     * @note       In case of NRF_ERROR_RESOURCES, remaining pattern that could not be transmitted
     *             can be enqueued \ref buffer_enqueue function.
     *             In case a pattern of 'cofFEe' is the p_key_pattern, with pattern_len as 6 and
     *             pattern_offset as 0, the notifications as observed on the peer side would be
     *             1>    'c', 'o', 'f', 'F', 'E', 'e'
     *             2>    -  , 'o', 'f', 'F', 'E', 'e'
     *             3>    -  ,   -, 'f', 'F', 'E', 'e'
     *             4>    -  ,   -,   -, 'F', 'E', 'e'
     *             5>    -  ,   -,   -,   -, 'E', 'e'
     *             6>    -  ,   -,   -,   -,   -, 'e'
     *             7>    -  ,   -,   -,   -,   -,  -
     *             Here, '-' refers to release, 'c' refers to the key character being transmitted.
     *             Therefore 7 notifications will be sent.
     *             In case an offset of 4 was provided, the pattern notifications sent will be from 5-7
     *             will be transmitted.
     */
    static uint32_t send_key_scan_press_release(ble_hids_t * p_hids,
                                                uint8_t    * p_key_pattern,
                                                uint16_t     pattern_len,
                                                uint16_t     pattern_offset,
                                                uint16_t   * p_actual_len)

    If you wait more than 500ms between key press and release, then at least for Windows it will treat this as a key repeat automatically until release it received.

  • Hi,

    Ok, but i see the code snippet in your response looks like corrupted, i see just the function declaration ?! is it the same one in the ble hid keyboard example in the sdk ?

    Best regards,

  • It's the same as the HID keyboard example yes, I only shared the description here.

Reply Children
No Data
Related