1 在C***AppUi::ConstructL()里面调用SetCaptureKey()
2 在TKeyResponse C***AppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,
TEventCode aType) 里面处理按键
这样既可。
NOTE:
1 在Container里面处理按键事件时,注意不要捕获的按键,记得return EKeyWasNotConsumed;
以便这里处理。
2 要捕获系统按键需要添加SwEvent能力。
思路:
基本思路:
首先程序运行时注册按键事件,然后将程序转入后台运行,当按键事件发生后在AppUi的HandleKeyEventL中处理。
参考自网络资源。捕获接听键成功。
//记得把按键信息传回去
// RWsSession iWsSession;
// User::LeaveIfError(iWsSession.Connect());
// TInt wgId = iWsSession.GetFocusWindowGroup(); //获取当前界面ID
// CApaWindowGroupName* gn = CApaWindowGroupName::NewLC(iWsSession, wgId);
// TUid uid = gn->AppUid();
// TWsEvent event;
// event.SetType(EEventKey);
// event.SetTimeNow();
// event.Key()->iCode = aKeyEvent.iCode;
// event.Key()->iModifiers = aKeyEvent.iModifiers;
// event.Key()->iRepeats = aKeyEvent.iRepeats;
// event.Key()->iScanCode = aKeyEvent.iScanCode;
// iWsSession.SendEventToWindowGroup(wgId, event);
// CleanupStack::PopAndDestroy(); //gn
// iWsSession.Close();