Discussion Board

Results 1 to 12 of 12
  1. #1
    Regular Contributor qt_chenchen's Avatar
    Join Date
    Jul 2008
    Posts
    51
    Guys,

    Can you give me an idea/suggestion on how can i capture the event wherein the power button is pressed?

    Thanks in advance..

  2. #2
    Nokia Developer Expert symbianyucca's Avatar
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    28,671
    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

  3. #3
    Regular Contributor ssn.kishore's Avatar
    Join Date
    Feb 2008
    Location
    Pune, India
    Posts
    340
    Hi Chenchen,

    Use the following snippet in your class' ConstructL()

    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);
    Once this is done, you'll receive the event your RunL() handle it something like the snippet below,

    Code:
    iWsSession.GetEvent(iWsEvent);
    
    	switch(*(TApaSystemEvent*)(iWsEvent.EventData()))
    	{
    		case EApaSystemEventShutdown:
    		{
                         // Do the needful
    		}
    Hope it helps!
    Regards,
    Sainagakishore Srikantham (Kishore)

    Don't Hope, KNOW!!! ---------- Visit me at http://ssnkishore.blogspot.com ----------

  4. #4
    Regular Contributor NevePankaj's Avatar
    Join Date
    Jul 2008
    Posts
    179
    Quote Originally Posted by qt_chenchen View Post
    Guys,

    Can you give me an idea/suggestion on how can i capture the event wherein the power button is pressed?

    Thanks in advance..
    Hi,

    You can check for the key capture example at wiki
    the key code for power key is EKeyDevice2.

  5. #5
    Registered User Jick's Avatar
    Join Date
    Feb 2009
    Location
    Russia
    Posts
    70
    Hi! I'm trying to use ssn.kishore's code example. But when my application is running PowerKey became unavallibe. Why can it be?

  6. #6
    Nokia Developer Expert symbianyucca's Avatar
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    28,671
    Quote Originally Posted by Jick View Post
    Hi! I'm trying to use ssn.kishore's code example. But when my application is running PowerKey became unavallibe. Why can it be?
    Because you are capturing it, it wont be available for others.. thus you would need to disable the capturing once you do not need the key anymore.

  7. #7
    Registered User Jick's Avatar
    Join Date
    Feb 2009
    Location
    Russia
    Posts
    70
    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.

  8. #8
    Nokia Developer Expert symbianyucca's Avatar
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    28,671
    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.

  9. #9
    Registered User Jick's Avatar
    Join Date
    Feb 2009
    Location
    Russia
    Posts
    70
    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();
    }
    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();
    }
    RunL is calling when I'm pressing PowerKey, but event is not sending to window group and string WriteLog(KPower()) never execute.
    Last edited by Jick; 2011-03-18 at 11:23.

  10. #10
    Registered User Jick's Avatar
    Join Date
    Feb 2009
    Location
    Russia
    Posts
    70
    Please help!
    |
    V

  11. #11
    Nokia Developer Expert symbianyucca's Avatar
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    28,671
    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.

  12. #12
    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();
    	}
    }

Similar Threads

  1. Image capture button in N90
    By jini_1 in forum Mobile Java General
    Replies: 2
    Last Post: 2006-11-16, 23:55
  2. getting ok button pressed
    By csIndia in forum Mobile Java General
    Replies: 4
    Last Post: 2006-08-09, 08:31
  3. How can capture "Pen" button ?
    By comb in forum Symbian C++
    Replies: 0
    Last Post: 2005-04-07, 10:56
  4. How to capture joystick center button?
    By gauravgandhi80 in forum Symbian C++
    Replies: 1
    Last Post: 2004-12-29, 07:01
  5. Series 60 - Power button, and starting process in background
    By pandeya in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2004-11-01, 09:04

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved