<?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>HID Mouse click and hold confusion</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/82/hid-mouse-click-and-hold-confusion</link><description>I have modified the included HID mouse example to allow for left/right/middle mouse clicks. However, it is not clear to me how to set an event handler for both when a button goes HIGH as well as LOW using the button handler module. 
 static void buttons_init</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 09 Jul 2013 11:29:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/82/hid-mouse-click-and-hold-confusion" /><item><title>RE: HID Mouse click and hold confusion</title><link>https://devzone.nordicsemi.com/thread/457?ContentTypeID=1</link><pubDate>Tue, 09 Jul 2013 11:29:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ee1ce5ab-675b-41e1-a00c-5cbcc2a4226c</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The GPIO sense is set to either high or low level. You will not be able to get interrupt on both rising and falling edge. What we have done in our reference design (nrfready desktop 2) is that we poll the buttons (each 15ms) using app_timer and store the previous result to see if there is any change.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void button_handler(void* p_context)
{
    static uint8_t prev_buttons     = 0;
    static uint8_t prev_adv_buttons = 0;
    uint8_t        buttons          = 0;
    uint8_t        adv_buttons      = 0;
    uint32_t       all_lines;
    
    // Read button state
    all_lines = drv_mouse_btn_read();    
   
    // Check which buttons are held and flip interrupt sense polarity of those who are
    if (all_lines &amp;amp; IO_BTN_LEFT_MSK)
    {
        buttons |= (1 &amp;lt;&amp;lt; 0);
    }
    
    if (all_lines &amp;amp; IO_BTN_RIGHT_MSK)
    {
        buttons |= (1 &amp;lt;&amp;lt; 1);
    }
    
    if (all_lines &amp;amp; IO_BTN_MIDDLE_MSK)
    {
        buttons |= (1 &amp;lt;&amp;lt; 2);
    }  
    
    if (all_lines &amp;amp; IO_BTN_SIDE_LEFT_MSK)
    {
        buttons |= (1 &amp;lt;&amp;lt; 3);
    }
    
    if (all_lines &amp;amp; IO_BTN_SIDE_RIGHT_MSK)
    {
        buttons |= (1 &amp;lt;&amp;lt; 4);
    }
    
    if ((all_lines &amp;amp; IO_BTN_RESET_MSK) == IO_BTN_RESET_MSK)
    {    
        // Pairing button combo has been pressed. Sending empty event to indicate this
        s_event_handler(0, 0);
    }
    
    if (buttons != prev_buttons)
    {
        mouse_data_t data;

        data.type                 = packet_type_mouse_buttons;
        data.packet.mouse_buttons = buttons;
        
        s_event_handler(&amp;amp;data, sizeof(data));
        
        prev_buttons = buttons;
    }
    
    if (adv_buttons != prev_adv_buttons)
    {
        mouse_data_t data;

        data.type                     = packet_type_mouse_adv_buttons;
        data.packet.mouse_adv_buttons = adv_buttons;

        s_event_handler(&amp;amp;data, sizeof(data));
        
        prev_adv_buttons = adv_buttons;
    }
    
    if ((adv_buttons == 0) &amp;amp;&amp;amp; (buttons == 0))
    {
        app_timer_stop(s_timer_id);
        s_timer_running = false;
        drv_mouse_btn_sense_enable(true);
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>