Discussion Board

Results 1 to 8 of 8
  1. #1
    Regular Contributor razas's Avatar
    Join Date
    Jul 2005
    Posts
    95
    Hi !


    First of all Id like you to forgive a Symbian C++ novice (thats me !!!) for asking a question thats been asked so many times on this forum.Having said that,let me proceed...puhleeez ;)
    I wrote an application that goes into the background and after 5 secs comes back to the foreground. What I want to do now is that instead of the preset time interval of 5 secs the application should come to the foreground whenever a key is pressed by the user.
    I know about the CaptureKey() event of the RWindowGroup class. However ,being new to Symbian C++, I was not able to make much sense of the sdk docs . The code fragments that I came across in the forums gave me some idea but Im still not able to implement the functionality I want.
    Hence Id really appreciate it if you could provide me a link to some tutorial or complete source code that demonstrates the CaptureKey() method in detail.

    Thank you. :-)

  2. #2
    Regular Contributor jtjk's Avatar
    Join Date
    Mar 2003
    Location
    Tampere, Finland
    Posts
    53
    Look SDK help for TApaTask (BringToForeground) and TApaTaskList

  3. #3
    Regular Contributor giridharn's Avatar
    Join Date
    Oct 2004
    Location
    india
    Posts
    306
    include this code in ur container/view class constructl

    iEikonEnv->RootWin().CaptureKey( EKeyYes, 0, 0 );
    iEikonEnv->RootWin().CaptureKeyUpAndDowns( EKeyYes, 0, 0 );


    upon apps moving background....


    TKeyResponse CHelloWorldAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
    {
    if ( aKeyEvent.iCode== EKeyYes )
    {

    iEikonENv->AlertWin(_L("keycaptured"));
    return EKeyWasConsumed;
    }
    return EKeyWasNotConsumed;
    }

  4. #4
    Regular Contributor razas's Avatar
    Join Date
    Jul 2005
    Posts
    95
    Hi !

    I have the following code

    Code:
    TKeyResponse CAppInBackgroundContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
    {
    
      
         
      if ( aKeyEvent.iCode== EKeyYes )
    {
    
    iEikonEnv->AlertWin (_L("keycaptured"));
    return EKeyWasConsumed;
    }
    return EKeyWasNotConsumed;
    
     iLog.Write(_L("### OfferKeyEventL called ###")); //Log this call
    
    
    }
    And the ConstructL is as follows

    Code:
    void CAppInBackgroundContainer::ConstructL(const TRect& aRect)
    {
      CreateWindowL();
      SetRect(aRect);
      InitComponentsL();
      ActivateL();
    
      User::LeaveIfError(iLog.Connect());
      iLog.CreateLog(_L("AppInBackground"),_L("AppInBackgroundLog"), EFileLoggingModeOverwrite);
      iLog.Write(_L("### ConstructL(const TRect& aRect) = 1 ###"));
        
      
     iEikonEnv->RootWin().CaptureKey( EKeyYes, 0, 0 );
    iEikonEnv->RootWin().CaptureKeyUpAndDowns( EKeyYes, 0, 0 ); 
    
    }
    It appears from the log that OfferKeyEventL() gets called immediately after ConstructL() and not when any key is pressed while the application is in the background.
    I tried replacing EkeyYes with EKeyDial and even that didnt work. Could you plz tell me what am I doing wrong ?

    Thank you :-)

  5. #5
    Regular Contributor giridharn's Avatar
    Join Date
    Oct 2004
    Location
    india
    Posts
    306
    i modified ur code plzz chk this way
    Code:
    TKeyResponse CAppInBackgroundContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
    {
    
      iLog.Write(_L("### OfferKeyEventL called ###")); //Log this call
         
      if ( aKeyEvent.iCode== EKeyYes )
    {
    
    iEikonEnv->AlertWin (_L("keycaptured"));
    return EKeyWasConsumed;
    }
    return EKeyWasNotConsumed;
    
     
    
    
    }
    And the ConstructL is as follows

    Code:
    void CAppInBackgroundContainer::ConstructL(const TRect& aRect)
    {
      CreateWindowL();
      SetRect(aRect);
      InitComponentsL();
      
    
      User::LeaveIfError(iLog.Connect());
      iLog.CreateLog(_L("AppInBackground"),_L("AppInBackgroundLog"), EFileLoggingModeOverwrite);
      iLog.Write(_L("### ConstructL(const TRect& aRect) = 1 ###"));
        
      
     iEikonEnv->RootWin().CaptureKey( EKeyYes, 0, 0 );
    iEikonEnv->RootWin().CaptureKeyUpAndDowns( EKeyYes, 0, 0 ); 
    ActivateL();
    }
    It appears from the log that OfferKeyEventL() gets called immediately after ConstructL() and not when any key is pressed while the application is in the background.
    I tried replacing EkeyYes with EKeyDial and even that didnt work. Could you plz tell me what am I doing wrong ?

    Thank you :-)[/QUOTE]

  6. #6
    Regular Contributor razas's Avatar
    Join Date
    Jul 2005
    Posts
    95
    Thanks gir, it works now :-)

  7. #7
    Registered User hmauricio's Avatar
    Join Date
    Jan 2005
    Posts
    27
    Hi!

    I am using the following code to test captureKey() in the case no action is made


    void CMyAppView::ConstructL(const TRect& aRect)
    {
    CreateWindowL();
    SetRect(aRect);
    windowGroup = CEikonEnv::Static()->RootWin();
    windowGroup.CaptureKey('#',0,0);
    ActivateL();
    }


    TKeyResponse CMyAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
    {
    return EKeyWasNotConsumed
    // or
    //return CCoeControl::OfferKeyEventL(aKeyEvent, aType);
    // none work
    }


    The problem is the framework never gets to haldle this key when the app is on. So this is the only app that is getting this keyEvent and never passes it to other app.

    What is the problem?

    Thanks

    Hugo

  8. #8
    Registered User hmauricio's Avatar
    Join Date
    Jan 2005
    Posts
    27
    Hey can someone halp me in my question!!!???!!?!?!?!?!?

    Hugo

Similar Threads

  1. Connect Nokia 7650 Emulator to Internet via modem/RAS on Win2000/WinXP Pro
    By Youth_Jack in forum Symbian Networking & Messaging (Closed)
    Replies: 5
    Last Post: 2006-02-05, 17:48
  2. Simulating Long Key Press event in debugging mode...
    By empeegee in forum Symbian C++
    Replies: 6
    Last Post: 2004-12-22, 05:24
  3. How to bring exe from background to foreground?
    By toughworker in forum Symbian C++
    Replies: 2
    Last Post: 2004-12-20, 00:01
  4. Replies: 1
    Last Post: 2004-11-24, 19:49
  5. Capturing Key Events when app is running in background
    By y10913 in forum Symbian User Interface
    Replies: 0
    Last Post: 2004-11-08, 19:57

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