Read-only archive of the All About Symbian forum (2001–2013) · About this archive

Handle keypress when app is in the background

0 replies · 4,140 views · Started 10 October 2005

Hi !

I need my application to handle a keypress say for example, Camera Key even when my application is in the background. The Camera key gets captured when my application is in the foreground but not when it is in the background.

I have the following code in the ConstructL() of my container class



CEikonEnv::Static()->RootWin().CaptureKey(0x0F852,0,0,2); //Handle Camera key

Then , in the OfferKeyEventL() of the container class I have the following code :

TKeyResponse CMyAppContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)

{


if(aType == EEventKey)
{

if(aKeyEvent.iCode == 0x0F853)//Camera
//...code to do something
else
//...code to do something else

}

return EKeyWasConsumed ;

}

The code to send my application to the background is as follows :


void CMyAppContainer::SendToBackground()
{

TApaTaskList tasklist(iCoeEnv->WsSession());
TApaTask task(tasklist.FindApp(_L("MyApp"😉));
task.SendToBackground();

iAppWasInBackground = 1 ;

iLog.Write(_L("Sent to background"😉);

}

However the above does not work when my application is in the background. On pressing the camera key the camera app does not launch which I suppose means that my application is registering the keypress. However, the OfferKeyEventL() never gets called when I press the camera key while my application is in the background.

Please help !!

Thanks a lot 😊