Using long-tap events

Long-tap events allow you to specify functions performed when the user taps and holds the button for a specified period of time. An example of a long-tap function is fast forwarding in a media player application by tapping and holding down a button.

To receive long-tap events, use the class CAknLongTapDetector in the Touch UI utilities API.

To enable the handling of long tap events in your CAknButton , set the flag KAknButtonReportOnLongPress for the button. When the long tap event starts,CAknButton::ELongPressEvent() is reported to the button observer (MCoeControlObserver). When the long tap event ends, CAknButton::ELongPressEndedEvent() is reported.

To define the period for which the button needs to be held down for a long-tap event, use the method SetLongPressInterval() in the class CAknButton.

void CMyAppContainer::ConstructL() 
{ 
… 
iButton = CAknButton::NewL( NULL, NULL, NULL, NULL, 

KNullDesC, KNullDesC , KAknButtonReportOnLongPress, 0 ); 

iButton->SetContainerWindowL( *this ); 
iButton->SetObserver( this ); 
… 
} 

void CMyAppContainer::HandleControlEventL( CCoeControl* aControl, 
                                                  TCoeEvent aEventType ) 
    { 
        switch ( aEventType ) 
            { 

// Button is pressed for a long time 

            case CAknButton::ELongPressEvent: 
                        if ( aControl == iButton ) 

{ 

                        … 

} 

                break; 

// Button long press ended 

            case CAknButton::ELongPressEndedEvent: 
                        if ( aControl == iButton ) 

{ 

                        … 

} 

                break; 

            default: 
                break; 
            } 
    }