截获按键事件


1.usual key

In CMyAppUi::ConstructL() I put:

iEikonEnv->RootWin().EnableReceiptOfFocus(ETrue);
captureEvent = iEikonEnv->RootWin().CaptureKey(EStdKeyMenu,0,0);

And in the destructor:

iEikonEnv->RootWin().CancelCaptureKey(captureEvent);


TKeyResponse CMyAppUi::HandleKeyEventL(
const TKeyEvent& KeyEvent,TEventCode aType)
{
TKeyResponse returnKey = EKeyWasNotConsumed;
if(aType == EEventKey)
{
switch(KeyEvent.iScanCode)
{
case EStdKeyMenu:
{
iAppContainer->SetTextL(_L("Menu key pressed"));
iEikonEnv->RootWin().SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront);
returnKey = EKeyWasConsumed;
break;
}
default:
{
returnKey = EKeyWasNotConsumed;
break;
}
}
}
return returnKey;
}

2.special keys:such as menu key:

EStdKeyMenu,EKeyMenu, EKeyApplication0, EStdKeyApplication0(menu keys)….are of TStdScanCode type…

if u want to use the TStdScanCode type…use captureKeyUpandDows() method…

CaptureKeyUpandDowns

3.muilty keys

  1. No comments yet.
(will not be published)

Switch to our mobile site