<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>BLE hid Keyboard key press/release [Clarifications needed]</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/57587/ble-hid-keyboard-key-press-release-clarifications-needed</link><description>Hi, 
 We&amp;#39;re working on a ble hid keyboard project, and we need some clarifications on how the keyboard keys press/release is done ! 
 We&amp;#39;ve started with the example in the sdk v16.0.0, the example uses the keys_send() function to send a press followed</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 04 Jan 2024 12:40:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/57587/ble-hid-keyboard-key-press-release-clarifications-needed" /><item><title>RE: BLE hid Keyboard key press/release [Clarifications needed]</title><link>https://devzone.nordicsemi.com/thread/462677?ContentTypeID=1</link><pubDate>Thu, 04 Jan 2024 12:40:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c157e1be-4c27-4fd0-b629-d2f804db63d0</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;For new development you should be using the nRF Connect SDK that have a very different implementation. Something like this example show:&amp;nbsp;&lt;br /&gt;&lt;a href="https://github.com/martelmy/NCS_examples/tree/main/peripherals/long_press_button"&gt;https://github.com/martelmy/NCS_examples/tree/main/peripherals/long_press_button&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To get familiar with nRF Connect SDK:&amp;nbsp;&lt;a href="https://academy.nordicsemi.com/"&gt;https://academy.nordicsemi.com/&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In any case, this post if 4 years old, so I am closing it.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE hid Keyboard key press/release [Clarifications needed]</title><link>https://devzone.nordicsemi.com/thread/462553?ContentTypeID=1</link><pubDate>Wed, 03 Jan 2024 15:07:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a66da4e8-78ae-4926-bb16-57fcaedee059</guid><dc:creator>bharatb4196</dc:creator><description>&lt;p&gt;Has anything been followed up on this, with the press and hold effect as I am in the same situation studying the example code, but finding it difficult to understand&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE hid Keyboard key press/release [Clarifications needed]</title><link>https://devzone.nordicsemi.com/thread/233970?ContentTypeID=1</link><pubDate>Wed, 12 Feb 2020 13:01:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3fc252fd-76e9-4e16-ac69-5958ebba9388</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;I am not sure what key code 0x04 is, however it would be interesting to get a sniffer log of the on-air communication here:&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ug_sniffer_ble/UG/sniffer_ble/intro.html"&gt;https://infocenter.nordicsemi.com/topic/ug_sniffer_ble/UG/sniffer_ble/intro.html&lt;/a&gt;&amp;nbsp;&lt;br /&gt;&lt;a href="https://www.nordicsemi.com/Software-and-tools/Development-Tools/nRF-Sniffer-for-Bluetooth-LE/Download#infotabs"&gt;https://www.nordicsemi.com/Software-and-tools/Development-Tools/nRF-Sniffer-for-Bluetooth-LE/Download#infotabs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE hid Keyboard key press/release [Clarifications needed]</title><link>https://devzone.nordicsemi.com/thread/233920?ContentTypeID=1</link><pubDate>Wed, 12 Feb 2020 10:11:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:99a6fcaa-f320-4c7f-a681-cb2459204bb1</guid><dc:creator>abdelali</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;thank you,&lt;/p&gt;
&lt;p&gt;Yes i did. and here is&amp;nbsp;the button handler i use to test it :&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void button_event_handler(uint8_t pin_no, uint8_t button_action)
{
  ret_code_t err_code;

  uint8_t  data[INPUT_REPORT_KEYS_MAX_LEN];

  switch(pin_no){

   case BUTTON_1:

      if(button_action == APP_BUTTON_PUSH) {
      
            memset(data, 0, sizeof(data));
            data[2] = 0x04;

            err_code = ble_hids_inp_rep_send(&amp;amp;m_hids,
                                             INPUT_REPORT_KEYS_INDEX,
                                             INPUT_REPORT_KEYS_MAX_LEN,
                                             data,
                                             m_conn_handle);

            if(err_code != NRF_SUCCESS) NRF_LOG_INFO(&amp;quot;err : %x; \n&amp;quot;,err_code); 

            NRF_LOG_INFO(&amp;quot;button1 PUSHED&amp;quot;);      
      
      }

     else if(button_action == APP_BUTTON_RELEASE) { 
     
           memset(data, 0, sizeof(data));    
           err_code = ble_hids_inp_rep_send(&amp;amp;m_hids,
                                             INPUT_REPORT_KEYS_INDEX,
                                             INPUT_REPORT_KEYS_MAX_LEN,
                                             data,
                                             m_conn_handle);

           if(err_code != NRF_SUCCESS) NRF_LOG_INFO(&amp;quot;err : %x; \n&amp;quot;,err_code); 

           NRF_LOG_INFO(&amp;quot;button1 RELEASED&amp;quot;);    

      }


     break;

 }

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But even that, the same output!&lt;/p&gt;
&lt;p&gt;[*] tested on an Android device :&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/Screenshot_5F00_20200212_5F00_110245_5F00_aws.apps.keyeventdisplay.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;Best Regards,&lt;/p&gt;
&lt;p&gt;Abdelali&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE hid Keyboard key press/release [Clarifications needed]</title><link>https://devzone.nordicsemi.com/thread/233899?ContentTypeID=1</link><pubDate>Wed, 12 Feb 2020 09:25:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ef6ad182-9fc1-4f0b-b1e6-c694699a11c0</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Have you tried to call&amp;nbsp;ble_hids_inp_rep_send() when pressing, and then&amp;nbsp;ble_hids_inp_rep_send() when releasing directly?&lt;/p&gt;
&lt;p&gt;Just make sure that the data buffer is 8 bytes, where the first 2 bytes (data[0] and data[1]) are key modifier (e.g. shift, num lock etc), so the actual key that is pressed is 3rd byte (data[2]) in the array. The remaining data bytes (data[3]-data[7]) can be 0.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE hid Keyboard key press/release [Clarifications needed]</title><link>https://devzone.nordicsemi.com/thread/233877?ContentTypeID=1</link><pubDate>Wed, 12 Feb 2020 07:44:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ca6d53f5-34e7-4301-957e-9a855e679136</guid><dc:creator>abdelali</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I have experimented with the send_key_scan_press_release() function, just sending a one key, and not even using the buffering feature.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For the press i just fill the data array with the scan code (1 key_pattern). and for the release i clear the data array.&lt;/p&gt;
&lt;p&gt;The BLE HID output seems to output a KEY PRESS followed by KEY RELEASE, a hold on the button will keep outputting a PRESS followed with a RELEASE.&lt;/p&gt;
&lt;p&gt;I even tried to only send a PRESS (by not clearing the data array); but that also sends a RELEASE after.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not quite sure how&amp;nbsp;the RELEASE event is sent right after the&amp;nbsp;PRESS, even without clearing the data[] variable!&lt;/p&gt;
&lt;p&gt;I Really appreciate any hints/guidance/documentation on how to implement it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best Regards,&lt;/p&gt;
&lt;p&gt;Abdelali&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static uint32_t send_key_scan_press_release(ble_hids_t * p_hids,
                                            uint8_t    * p_key_pattern,
                                            uint16_t     pattern_len,
                                            uint8_t      action )
{
    ret_code_t err_code;
    uint16_t data_len;
    uint8_t  data[INPUT_REPORT_KEYS_MAX_LEN];

    // HID Report Descriptor enumerates an array of size 6, the pattern hence shall not be any
    // longer than this.
    STATIC_ASSERT((INPUT_REPORT_KEYS_MAX_LEN - 2) == 6);

    ASSERT(pattern_len &amp;lt;= (INPUT_REPORT_KEYS_MAX_LEN - 2));

    data_len = pattern_len;   // 1

  if(action == 1){ // press

        // Reset the data buffer.
        memset(data, 0, sizeof(data));
        // Copy the scan code.
        memcpy(data + SCAN_CODE_POS , p_key_pattern , data_len );

        if (modifier_status)
        {
           data[MODIFIER_KEY_POS] |= ble_hid_config[11];//
        }

    }

  else { // release 
  
          // Reset the data buffer.
          memset(data, 0, sizeof(data));
    }

        if (!m_in_boot_mode)
        {
            err_code = ble_hids_inp_rep_send(p_hids,
                                             INPUT_REPORT_KEYS_INDEX,
                                             INPUT_REPORT_KEYS_MAX_LEN,
                                             data,
                                             m_conn_handle);
        }
        else
        {
            err_code = ble_hids_boot_kb_inp_rep_send(p_hids,
                                                     INPUT_REPORT_KEYS_MAX_LEN,
                                                     data,
                                                     m_conn_handle);
        }

        if (err_code != NRF_SUCCESS)
        {

         APP_ERROR_CHECK(err_code);

         }

    return err_code;
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE hid Keyboard key press/release [Clarifications needed]</title><link>https://devzone.nordicsemi.com/thread/233641?ContentTypeID=1</link><pubDate>Tue, 11 Feb 2020 08:04:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f7dcabce-91c1-4557-93c2-bbbd847a6ff9</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;It&amp;#39;s the same as the HID keyboard example yes, I only shared the description here.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE hid Keyboard key press/release [Clarifications needed]</title><link>https://devzone.nordicsemi.com/thread/233589?ContentTypeID=1</link><pubDate>Mon, 10 Feb 2020 15:47:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b3e45a20-3680-44e9-bcd8-0b3b40d8eaaa</guid><dc:creator>abdelali</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;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 ?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE hid Keyboard key press/release [Clarifications needed]</title><link>https://devzone.nordicsemi.com/thread/233465?ContentTypeID=1</link><pubDate>Mon, 10 Feb 2020 09:36:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e9663c3-cc66-4790-b7b6-7b3c546e1890</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Feel free to modify this as you see fit, also check out the api description:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief   Function for transmitting a key scan Press &amp;amp; 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 &amp;lt; pattern_len &amp;lt; 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 &amp;#39;cofFEe&amp;#39; 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&amp;gt;    &amp;#39;c&amp;#39;, &amp;#39;o&amp;#39;, &amp;#39;f&amp;#39;, &amp;#39;F&amp;#39;, &amp;#39;E&amp;#39;, &amp;#39;e&amp;#39;
 *             2&amp;gt;    -  , &amp;#39;o&amp;#39;, &amp;#39;f&amp;#39;, &amp;#39;F&amp;#39;, &amp;#39;E&amp;#39;, &amp;#39;e&amp;#39;
 *             3&amp;gt;    -  ,   -, &amp;#39;f&amp;#39;, &amp;#39;F&amp;#39;, &amp;#39;E&amp;#39;, &amp;#39;e&amp;#39;
 *             4&amp;gt;    -  ,   -,   -, &amp;#39;F&amp;#39;, &amp;#39;E&amp;#39;, &amp;#39;e&amp;#39;
 *             5&amp;gt;    -  ,   -,   -,   -, &amp;#39;E&amp;#39;, &amp;#39;e&amp;#39;
 *             6&amp;gt;    -  ,   -,   -,   -,   -, &amp;#39;e&amp;#39;
 *             7&amp;gt;    -  ,   -,   -,   -,   -,  -
 *             Here, &amp;#39;-&amp;#39; refers to release, &amp;#39;c&amp;#39; 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)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>