×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Feb 2009
    Location
    Russia
    Posts
    70

    Unhappy Can't capture keypress in background application

    Hi, all!

    I'm trying to do an application that I want to capture key preses staying in

    background using this example:

    http://wiki.forum.nokia.com/index.ph..._in_background

    Here is what I'm doing:

    - Creating new Symbian C++ class, named CapturingKeys(Type of class is "Simple

    Symbian Style C++ Class")

    - Putting there code from example

    - Adding ws32.lib apgrfx.lib and capability SwEvent

    - #include <w32std.h>
    #include <apgwgnam.h>

    - changing KeyCapBGAppUi.h

    Code:
    #ifndef __KEYCAPBGAPPUI_h__
    #define __KEYCAPBGAPPUI_h__
    #include "CapturingKeys.h"
    	...
    class CKeyCapBGAppUi : public CAknAppUi, public MKeyCallBack
    	{
    public:
    	...
    TBool KeyCapturedL(TWsEvent aEvent);
    private:
    	...
    private:
    	...
    CKeyCapturer *iKC;
    };
    #endif
    - changing KeyCapBGAppUi.cpp

    Code:
    	...
    void CKeyCapBGAppUi::ConstructL()
    	{
    	iKC = CKeyCapturer::NewL(*this);
    	...
    	}
    	...
    TBool CKeyCapBGAppUi::KeyCapturedL(TWsEvent aEvent)
    {
    	TApaTask task(iEikonEnv->WsSession( ));
    	task.SetWgId(CEikonEnv::Static()->RootWin().Identifier());
    	task.BringToForeground();
    	return EFalse;
    }
    	...
    - running application on emulator. It's compiling well, but it doesn't capture any

    key from background.


    Well... changing CapturingKeys.cpp
    replace string
    Code:
    iHandle = iWg.CaptureKey(EStdKeyHash, 0,0);
    with
    Code:
    iHandle = iWg.CaptureKey('#', 0,0);
    - Compiling... it run well but when I'm pressing #-key emulator is falling

    Also somewhere have found this example:
    Code:
    ...
    void CTry99AppUi::ConstructL()
    	{
    	// Initialise app UI with standard value.
    	BaseConstructL(CAknAppUi::EAknEnableSkin);
    	CEikonEnv::Static()->SetSystem( ETrue );
    	 
    	    // capture hash '#' key permanently
    	    iHashKeyHandle = 
    
    CEikonEnv::Static()->RootWin().CaptureKeyUpAndDowns(EStdKeyHash, 0, 0); 
    	 
    	    // set application priority to foreground priority even if it goes to 
    
    background
    	    CEikonEnv::Static()->WsSession().ComputeMode( 
    
    RWsSession::EPriorityControlDisabled );
    	 
    	    // Make the application a high priority application
    	    CEikonEnv::Static()->RootWin().EnableReceiptOfFocus( ETrue );
    	    CEikonEnv::Static()->RootWin().SetOrdinalPosition(0, 
    
    ECoeWinPriorityAlwaysAtFront);
    	// Create view object
    	iAppView = CTry99AppView::NewL(ClientRect());
    	TApaTask task(iEikonEnv->WsSession());
    	                    
    
    task.SetWgId(CEikonEnv::Static()->RootWin().Identifier());
    	                    task.SendToBackground();
    
    	}
    ...
    void CTry99AppUi::HandleForegroundEventL(TBool aForeground) 
        {
        // Make the application a high priority application
        if (aForeground)
            {
            CEikonEnv::Static()->RootWin().SetOrdinalPosition(0, 
    
    ECoeWinPriorityAlwaysAtFront);
            }
        }
    void CTry99AppUi::HandleWsEventL (const TWsEvent &aEvent, CCoeControl 
    
    *aDestination)
        {
        if (aEvent.Type() == EEventKey ||
            aEvent.Type() == EEventKeyUp ||
            aEvent.Type() == EEventKeyDown ||
            aEvent.Type() == EEventKeyRepeat)
            {
            // This is for switching back to Application when Hash key is pressed
            if (EStdKeyHash == aEvent.Key()->iScanCode && EEventKey == aEvent.Type())
                {
                TApaTask task(iEikonEnv->WsSession());
                task.SetWgId(CEikonEnv::Static()->RootWin().Identifier());
                task.BringToForeground();
     
                return;
                }
            }
     
            CAknAppUi::HandleWsEventL(aEvent, aDestination);
        }
    This application I even can't send to background - it is always on top...

    Can someone help me to do an application which can go background and will go foreground after pressing some key?

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,697

    Re: Can't capture keypress in background application

    If the emulator dies, you have actually succeeded in capturing the key. Just the handling part fails somewhere.
    The emulator itself closes because you have started it via your application. You can change that: http://wiki.forum.nokia.com/index.ph...arbide.c%2B%2B
    Enabling the error messages is also a good idea: http://wiki.forum.nokia.com/index.ph...ded_panic_code
    And after all you could just debug your code, place some breakpoints into event handlers/RunL-s, etc.
    However it is also possible to enable Just In Time debugging in the preferences of the emulator, then the debugger will show the point of failure. If you encounter some error message about ECMT manager, search for ecmt in the Wiki and fix the Java configuration.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Location
    Russia
    Posts
    70

    Re: Can't capture keypress in background application

    Thanks for the answer! I'll work on this!

  4. #4
    Registered User
    Join Date
    Apr 2010
    Posts
    17

    Re: Can't capture keypress in background application

    Jick can you send me the source code cpp,h of this capture key, i can not implement it right.. THANKS

  5. #5
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: Can't capture keypress in background application

    Quote Originally Posted by rilley View Post
    Jick can you send me the source code cpp,h of this capture key, i can not implement it right.. THANKS
    you could search our wiki for CaptureKey, there are ready made examples that you could use.

Similar Threads

  1. Replies: 2
    Last Post: 2013-02-19, 10:37
  2. Do Symbian rejects the Express Signing request on any Business Development ground?
    By arpit2agrawal in forum Symbian Signed Support, Application Packaging and Distribution and Security
    Replies: 23
    Last Post: 2009-02-19, 10:46
  3. Replies: 9
    Last Post: 2008-09-04, 07:22
  4. What is application running in background?
    By newnb in forum Symbian
    Replies: 3
    Last Post: 2007-01-08, 03:03

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×