s60平台处理按键

S60平台应用往往需要直接处理按键,主要有两种方法:


一.继承自CAknAppUi的实例使用HandleKeyEventL

TKeyResponse CxxxAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
if (aType==EEventKeyDown && (aKeyEvent.iScanCode == EStdKeyDevice0 ||
                                                   aKeyEvent.iScanCode == EStdKeyDevice1 ))
         { //按左右功能键的处理 }
else { //按非左右功能键的处理 }
return( EKeyWasNotConsumed );
}


二.继承自CCoeControl的实例使用OfferKeyEventL

TKeyResponse CxxxContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
{
if ( aType == EEventKey )
      {
        if ( aKeyEvent.iScanCode == EStdKeyDevice0 )
          { //按左功能键的处理 return( EKeyWasNotConsumed ); }
        if ( aKeyEvent.iScanCode == EStdKeyDevice1 )
          { //按右功能键的处理 return( EKeyWasNotConsumed ); }
       }
return CCoeControl::OfferKeyEventL( aKeyEvent, aType );
}