Guys,
Can you give me an idea/suggestion on how can i capture the event wherein the power button is pressed?
Thanks in advance..![]()
Guys,
Can you give me an idea/suggestion on how can i capture the event wherein the power button is pressed?
Thanks in advance..![]()
We have a nice search facility here, so next time you could maybe try it out: http://discussion.forum.nokia.com/fo...t=power+button
Hi Chenchen,
Use the following snippet in your class' ConstructL()
Once this is done, you'll receive the event your RunL() handle it something like the snippet below,Code:User::LeaveIfError( iWsSession.Connect() ); iWindowGroup = new (ELeave) RWindowGroup ( iWsSession ); User::LeaveIfError( iWindowGroup->Construct( (TUint32)iWindowGroup, EFalse ) ); iWindowGroup->SetOrdinalPosition(-1); iWindowGroup->EnableReceiptOfFocus(EFalse); CApaWindowGroupName* wn = CApaWindowGroupName::NewLC(iWsSession); wn->SetHidden(ETrue); wn->SetWindowGroupName(*iWindowGroup); CleanupStack::PopAndDestroy(); // wn User::LeaveIfError(iWindowGroup->EnableFocusChangeEvents()); User::LeaveIfError(iWindowGroup->EnableOnEvents(EEventControlAlways)); User::LeaveIfError(iWindowGroup->EnableOnEvents()); iWindowGroup->CaptureKey(EKeyDevice2, EModifierAlt|EModifierCtrl, EModifierCtrl); CActiveScheduler::Add(this);
Hope it helps!Code:iWsSession.GetEvent(iWsEvent); switch(*(TApaSystemEvent*)(iWsEvent.EventData())) { case EApaSystemEventShutdown: { // Do the needful }
Regards,
Sainagakishore Srikantham (Kishore)
Don't Hope, KNOW!!! ---------- Visit me at http://ssnkishore.blogspot.com ----------
Hi,
You can check for the key capture example at wiki
the key code for power key is EKeyDevice2.
Hi! I'm trying to use ssn.kishore's code example. But when my application is running PowerKey became unavallibe. Why can it be?
My application always work in background and if I'm capturing number keys they work normal.
Is it possible to capture PowerKey the same way? I mean it must work as usual and my app also must get notification of PowerKey press.
Do check you key capturing codes for numbers, you are propably forwarding the keys to the focus application, and if you are doing the same with power key, then I'm assuming that it is not working that way.
That's right! Thanks!
But anyway something goes wrong...
Code:void CKeyCapturer::ConstructL() { User::LeaveIfError(iWsSession.Connect()); iWg = RWindowGroup(iWsSession); User::LeaveIfError(iWg.Construct((TUint32)&iWg, EFalse)); iWg.SetOrdinalPosition(-1, ECoeWinPriorityNormal+2 ); iWg.EnableReceiptOfFocus(EFalse); CApaWindowGroupName* wn = CApaWindowGroupName::NewLC(iWsSession); wn->SetHidden(ETrue); wn->SetWindowGroupName(iWg); CleanupStack::PopAndDestroy(); User::LeaveIfError(iWg.CaptureKey(EKeyDevice2, 0,0)); CActiveScheduler::Add(this); SetActive(); }RunL is calling when I'm pressing PowerKey, but event is not sending to window group and string WriteLog(KPower()) never execute.Code:void CKeyCapturer::RunL() { WriteLog(_L8("RunL")); TWsEvent e; iWsSession.GetEvent(e);. TInt type = e.Type(); if (type == EEventKeyDown) { if (e.Key()->iScanCode == EStdKeyDevice2 || e.Key()->iCode == EKeyDevice2) { WriteLog(KPower()); } } TInt wgId = iWsSession.GetFocusWindowGroup(); iWsSession.SendEventToWindowGroup( wgId, e ); Listen(); }
Last edited by Jick; 2011-03-18 at 11:23.
What excatly happens ?
if the problem is that after you start capturing the key, the key stops working, and if the SendEventToWindowGroup() does not work, then could indeed be that the power key is originally also using key capturing, and thus you would not be able to forward it by simply forwarding it to the focus window. I would not know any other ways really to do the forwarding, and sofor could be that it woulnd't be too good idea to capture that key, and you migth want to research for alternatives for your use case.
I have same problem. But i found solution. You must send to all window groups this key event. I use folowing code for this.
In function RunL
Code:void CKeyCapturer::RunL(){ if (iStatus == KErrNone) { TWsEvent e; iWsSession.GetEvent(e); if(iObserver.KeyCapturedL(e)){ TInt myIwgID = iWg.Identifier(); TInt numWindowGroups = iWsSession.NumWindowGroups(); CArrayFixFlat<TInt>* windowGroupList = new(ELeave) CArrayFixFlat<TInt>(numWindowGroups); CleanupStack::PushL(windowGroupList); User::LeaveIfError(iWsSession.WindowGroupList(windowGroupList)); for (TInt i = 0; i < windowGroupList->Count(); ++i){ TInt wgId = windowGroupList->At(i); if(wgId==myIwgID) continue; iWsSession.SendEventToWindowGroup(wgId, e); } CleanupStack::PopAndDestroy();//windowGroupList } } if (iStatus != KErrCancel) { Listen(); } }