×

Discussion Board

Page 6 of 8 FirstFirst 12345678 LastLast
Results 76 to 90 of 107
  1. #76
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    287

    Re: long keypress When program is run background??

    Quote Originally Posted by neel.soft View Post
    Can u plz show ur code,then only we can help u out? show basic lines u have implemented.

    my code is attached below

    Code:
    #include "GlobalLongKeyCapture.h"
    #include <e32base.h>
    #include <e32std.h>
    #include <e32cons.h>            // Console
    #include <apgwgnam.h>           // CApaWindowGroupName
    
    
    //  Constants
    // Text strings created by wizard
    _LIT( KTextConsoleTitle, "Console" );
    _LIT( KTextFailed, " failed, leave code = %d" );
    _LIT( KTextPressAnyKey, "\n[press any key to exit]\n" );
    
    // Key to listen to 
    const TUint KKeyCode = EKeyLeftArrow;
    
    // Capture KNumberOfPressesToCapture key presses
    const TInt KNumberOfPressesToCapture = 3;
    
    //  Global Variables
    // write all messages to this console
    LOCAL_D CConsoleBase* console;  
    
    
    //  Local Functions
    LOCAL_C void MainL(const TDesC& /*aArgs*/)
        {
    	console->Write( _L( "Starting key capturing\n" ) );
    	// Create capturer
    	CGlobalCapturer* capturer = new (ELeave) CGlobalCapturer();
    	CleanupStack::PushL( capturer );
    	// And start capturing
    	capturer->StartCapturingL();
    
    	// In a real application you should use CActiveSchedulerWait,
    	// but in this small demo application we know that there is just
    	// a single inner loop and no CActiveSchedulerWait "protection" is
    	// needed
    	CActiveScheduler::Start();
    	// Cleanup. Demo completed
    	CleanupStack::PopAndDestroy( capturer );
        }
    
    // Main function. Is TRAPD outside, in Start()
    LOCAL_C void DoStartL()
        {
        // Create active scheduler (to run active objects)
        CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
        CleanupStack::PushL(scheduler);
        CActiveScheduler::Install(scheduler);
    
        // Call main function with command line
    	// Command line is not really needed for this demo, but
    	// why not to demonstrate this either?
        TBuf<256> cmdLine;
        RProcess().CommandLine( cmdLine );
        MainL( cmdLine );
    
        // Delete active scheduler
        CleanupStack::PopAndDestroy(scheduler);
        }
    GLDEF_C TInt E32Main()
    	{
    	// Create cleanup stack
    	__UHEAP_MARK;
    	CTrapCleanup* cleanup = CTrapCleanup::New();
    
    	// Create output console
    	TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen)));
    	if (createError)
    		return createError;
    
    	// Run application code inside TRAP harness, wait keypress when terminated
    	TRAPD(mainError, DoStartL());
    	if (mainError)
    		console->Printf(KTextFailed, mainError);
    	console->Printf(KTextPressAnyKey);
    	console->Getch();
    	
    	delete console;
    	delete cleanup;
    	__UHEAP_MARKEND;
    	return KErrNone;
    	}
    
    //  Global Functions
    
    GLDEF_C TInt Start()
        {
        // Create cleanup stack
        __UHEAP_MARK;
        CTrapCleanup* cleanup = CTrapCleanup::New();
    
        // Create output console
        TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen)));
        if (createError)
            return createError;
    
        // Run application code inside TRAP harness, wait keypress when terminated
        TRAPD(mainError, DoStartL());
        if (mainError)
            console->Printf(KTextFailed, mainError);
        console->Printf(KTextPressAnyKey);
        console->Getch();
        
        delete console;
        delete cleanup;
        __UHEAP_MARKEND;
        return KErrNone;
        }
    
    ////////////////////////////////////
    // CGlobalCapturer
    ////////////////////////////////////
    
    // Constructor
    CGlobalCapturer::CGlobalCapturer() :
    	CActive( EPriorityNormal )
    	{
    	// nothing
    	}
    
    // Destructor
    CGlobalCapturer::~CGlobalCapturer()
    	{
    	delete iWindowGroupName;
    	delete iWindowGroup;
    	iWsSession.Close();
    	}
    
    // Cancel listening to key presses
    void CGlobalCapturer::DoCancel()
    	{
    	iWindowGroup->CancelCaptureLongKey( iCaptureHandle );
    	iWindowGroup->CancelCaptureKey( iCaptureHandle );
    	}
    
    void CGlobalCapturer::StartCapturingL() 
    	{
    	// Connect to the window server
    	User::LeaveIfError( iWsSession.Connect() );
    	// Create an invisible window group. Well, we'll make it invisible later
    	/** @todo Can ELeave be used with R-classes? */
    	iWindowGroup = new (ELeave) RWindowGroup ( iWsSession );
    	// @see RBlankWindow::Construct
    	iWindowGroup->Construct( (TUint32)iWindowGroup, EFalse );
    
    	// You cannot just call CaptureLongKey for the same key code
    	// You MUST call CaptureKey first
    	User::LeaveIfError( iCaptureHandle = iWindowGroup->CaptureKey( KKeyCode , 0, 0 ) );
    	// And finally capture long key presses
    	User::LeaveIfError( iLongCaptureHandle = iWindowGroup->CaptureLongKey( KKeyCode , KKeyCode, 0, 0, 0, 0 ) );
    	// Send created window to the background and hide it from the
    	// application switcher
    	iWindowGroup->SetOrdinalPosition(-1);
    	iWindowGroup->EnableReceiptOfFocus( EFalse );
    	iWindowGroupName = CApaWindowGroupName::NewL( iWsSession );
    	iWindowGroupName->SetHidden(ETrue);
    	iWindowGroupName->SetWindowGroupName( *iWindowGroup );
    
    	// Tell window server, that we are ready to receive events
    	iWsSession.EventReady( &this->iStatus );
    	CActiveScheduler::Add( this );
    	SetActive();
    	}
    
    // Key press happened
    void CGlobalCapturer::RunL()
    	{
    	if( iStatus == KErrNone ) 
    		{
    		// EEventKey received
    		console->Write( _L( "Captured key press\n" ) );
    		TWsEvent we;
    		iWsSession.GetEvent( we );
    
    		if( we.Key()->iCode == KKeyCode ) 
    			{
    			if( we.Key()->iRepeats == 0 )
    				{
    				console->Printf( _L( "Capture %i. Short key press\n" ), ++iCaptureCounter );
    				}
    			else
    				{
    				console->Printf( _L( "Capture %i. Long key press\n" ), ++iCaptureCounter );
    				}
    			}
    		else 
    			{
    			// This should never happen, but just to demonstrate how 
    			// it is possible to forward events to the default destination
    			TInt foregroundAppId = iWsSession.GetFocusWindowGroup();
    			iWsSession.SendEventToWindowGroup( foregroundAppId, we );
    			}  // if iCode
    		if( iCaptureCounter == KNumberOfPressesToCapture ) 
    			{
    			// exit MainL() inner loop
    			CActiveScheduler::Stop();
    			}
    		else 
    			{
    			iWsSession.EventReady( &iStatus );
    			SetActive();
    			}  // if captured enough times
    		}  // if iStatus
    	else 
    		{
    		// Framework notified of some error
    		/** @todo Handle error if required */
    		}
    	}
    
    //  Exported Functions
    
    #ifdef __WINS__
    EXPORT_C TInt WinsMain(TAny* /*aParam*/)
        {
        return Start();
        }
    #else
    GLDEF_C TInt E32Main()
        {
        return Start();
        }
    #endif
    
    #ifdef __WINS__
    TInt E32Dll(TDllReason /*aReason*/)
        {
        return KErrNone;
        }
    #endif
    
    
    // End of file

  2. #77
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    95

    Re: long keypress When program is run background??

    hi,

    U have just copied the whole code from forum ,now make it as per ur requirement .Avoid the extra line of code which u do not require and try some editing to check the flow of code.

    try making debug files after each line of code to check exactly where it is crashing and try it out on device.

  3. #78
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    287

    Re: long keypress When program is run background??

    Sir,
    Can u please specify whether this application (long key press when program is run backgronund) is possible by using S40 series.Do you have any suggesation about doing this in any other langauge.

  4. #79
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: long keypress When program is run background??

    not in S40 for sure.
    Amit Kankani
    Nokia Developer Champion

  5. #80
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    287

    Re: long keypress When program is run background??

    Sir,
    Can u please specify whether this application (long key press when program is run backgronund) is possible by using S40 series.Do you have any suggesation about doing this in any other langauge

  6. #81
    Nokia Developer Champion
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: long keypress When program is run background??

    Since no SDK available in C++ for S40, you may get better answer from Java guys.
    please ask same in following forum.
    http://discussion.forum.nokia.com/fo...isplay.php?f=3

  7. #82
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    287

    Re: long keypress When program is run background??

    sir

    i have made EXE for long key press when program is running in background i can't launch this on my emulator

  8. #83
    Nokia Developer Champion
    Join Date
    Mar 2006
    Location
    Helsinki, Finland
    Posts
    8,335

    Re: long keypress When program is run background??

    Quote Originally Posted by arun09 View Post
    sir

    i have made EXE for long key press when program is running in background i can't launch this on my emulator
    You can debug your application and see where control flow goes.
    Nokia Developer Wiki Moderation team

  9. #84
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    287

    Re: long keypress When program is run background??

    sir

    i write a program which have the function "While we make a 'long keypress'a message will be sent from my mobile ". this is working N95 but this is not working N80

    My log file is


    CGlobalCapturer: StartCapturingL...
    CGlobalCapturer: StartCapturingL Exiting...
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: StartCapturingL...
    CGlobalCapturer: StartCapturingL Exiting...
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: StartCapturingL...
    CGlobalCapturer: StartCapturingL Exiting...
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.
    CGlobalCapturer: RunL err [0]...
    CGlobalCapturer: RunL Key Code [50] foregroundAppId [0x18]...
    CGlobalCapturer: RunL.

  10. #85
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    287

    Re: long keypress When program is run background??

    sir

    please say foregroundAppId [0x18]... of N80

  11. #86
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    287

    Re: long keypress When program is run background??

    sir ,



    HelloWorldbasic_0xE4D50DDA.UID.CPP
    mwldsym2.exe: Undefined symbol: 'int E32Main(void) (?E32Main@@YAHXZ)'
    mwldsym2.exe: referenced from '__E32Startup' in uc_exe.cpp:46 (EEXE.LIB)

  12. #87
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: long keypress When program is run background??

    Quote Originally Posted by arun09 View Post
    sir ,



    HelloWorldbasic_0xE4D50DDA.UID.CPP
    mwldsym2.exe: Undefined symbol: 'int E32Main(void) (?E32Main@@YAHXZ)'
    mwldsym2.exe: referenced from '__E32Startup' in uc_exe.cpp:46 (EEXE.LIB)
    How this Compilation Error is Related to Original Post ? Please create 1 thread per Problem.

  13. #88
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    95

    Re: long keypress When program is run background??

    hi,

    Do U WANT TO DO IT ON S40 OR S60????

    I DONT HAVE ANY IDEA ABT S40??BUT FOR S60.....

    1.U CANNOT CHECK AN BACKGROUND EXE ON EMULATOR.

    2.I WLD SUGGEST U TO MAKE DEBUGFILE AFTER EACH AND EVERY LINE OF UR CODE TO SEE WHERE IT CRASHES...

    3.REMEMBER TO MAKE IT(THE EXE AS) FR,RI IN THE PACKAGE FILE.CHECK WHICH FILES ARE MADE AND WHICH ARE NOT. THEN PLZ SPECIFY THE EXACT LINE WHERE UR APP CRASHES AND TRY TO GET THE ERROR CODE.IT WILL BE EASIER TO HELP U OUT...

    4.FOR CAPTURING KEY EVENTS U MUST REQUIRE SWEvent Capabilty.plz add it into ur mmp file.

  14. #89
    Nokia Developer Champion
    Join Date
    Mar 2006
    Location
    Helsinki, Finland
    Posts
    8,335

    Re: long keypress When program is run background??

    Quote Originally Posted by neel.soft View Post
    1.U CANNOT CHECK AN BACKGROUND EXE ON EMULATOR.
    WHY? DID YOU TRY IT? IT WORKS FOR ME.
    Nokia Developer Wiki Moderation team

  15. #90
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    413

    Re: long keypress When program is run background??

    hi all,



    i have developed console application for capturing long key press for key '5'.My application always runs in a background.I am successfully able to capture long key press and i am writing a message in log file that key press is detected.

    But i have a problem.When i press key 5(Short or long) my screen hangs.I have to press Menu button explicitly to remove that hangness.

    I will give the code i have used. Please correct me if i am wrong anywhere.


    /*
    ============================================================================
    Name : LongKeyCapture.cpp
    Author : Rohan
    Copyright : Your copyright notice
    Description : Exe source file
    ============================================================================
    */

    // Include Files

    #include "LongKeyCapture.h"

    #include <e32base.h>
    #include <e32std.h>
    #include <e32cons.h> // Console
    #include <apgwgnam.h>
    #include <APGTASK.h>
    #include <W32STD.H>

    #include "logFile.h"


    // Constants

    _LIT(KTextConsoleTitle, "Console");
    _LIT(KTextFailed, " failed, leave code = %d");
    _LIT(KTextPressAnyKey, " [press any key]\n");


    // Key to listen to
    const TUint KKeyCode ='5';

    // Capture KNumberOfPressesToCapture key presses
    const TInt KNumberOfPressesToCapture = 5000;



    // Global Variables
    LOCAL_D CConsoleBase* console; // write all messages to this
    LOCAL_D LogFile* myLogFile; //Log File Class Object

    // Local Functions

    /*--- Create Log File ---*/
    LOCAL_C void CreateLogFile()
    {

    /*Create Log File : Only For Testing Purpose*/
    const TDesC& aPath(_L("C:\\Data\\LongKeyCapture.txt"));
    myLogFile = LogFile::NewL(aPath);

    }
    //end of CreateLogFile




    LOCAL_C void MainL()
    {
    // console->Write( _L( "Starting key capturing\n" ) );

    RWsSession iSession ;
    User::LeaveIfError( iSession.Connect() ) ;
    RWindowGroup iWindowGroup( iSession ) ;
    TApaTaskList iTaskList( iSession ) ;
    TApaTask iCurrentTask = iTaskList.FindByPos( 0 );
    TInt iWindowId = iCurrentTask.WgId() ;
    iCurrentTask.SetWgId( iWindowId ) ;
    iCurrentTask.SendToBackground() ;
    iWindowGroup.Close() ;
    iSession.Close() ;

    TRAPD(logFileCreationError,CreateLogFile());
    if(logFileCreationError == KErrNone)
    {
    myLogFile->WriteLog(_L8("Success : Log File Creation"));
    }
    else
    {
    myLogFile->WriteLog(_L8("Error : Log File Creation"));
    }

    // Create capturer
    CGlobalCapturer* capturer = new (ELeave) CGlobalCapturer();
    CleanupStack::PushL( capturer );
    // And start capturing
    capturer->StartCapturingL();

    // In a real application you should use CActiveSchedulerWait,
    // but in this small demo application we know that there is just
    // a single inner loop and no CActiveSchedulerWait "protection" is
    // needed
    CActiveScheduler::Start();
    // Cleanup. Demo completed
    CleanupStack::PopAndDestroy( capturer );
    }

    // Main function. Is TRAPD outside, in Start()
    LOCAL_C void DoStartL()
    {
    // Create active scheduler (to run active objects)
    CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
    CleanupStack::PushL(scheduler);
    CActiveScheduler::Install(scheduler);

    // Call main function with command line
    // Command line is not really needed for this demo, but
    // why not to demonstrate this either?
    // TBuf<256> cmdLine;
    // RProcess().CommandLine(cmdLine);
    MainL();

    // Delete active scheduler
    CleanupStack::PopAndDestroy(scheduler);
    }

    // Global Functions

    GLDEF_C TInt Start()
    {
    // Create cleanup stack
    __UHEAP_MARK;
    CTrapCleanup* cleanup = CTrapCleanup::New();

    // Create output console
    TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen)));
    if (createError)
    return createError;

    // Run application code inside TRAP harness, wait keypress when terminated
    TRAPD(mainError, DoStartL());
    // if (mainError)
    // console->Printf(KTextFailed, mainError);
    // console->Printf(KTextPressAnyKey);
    console->Getch();

    delete console;
    delete cleanup;
    __UHEAP_MARKEND;
    return KErrNone;
    }

    ////////////////////////////////////
    // CGlobalCapturer
    ////////////////////////////////////

    // Constructor
    CGlobalCapturer::CGlobalCapturer() :
    CActive( EPriorityNormal )
    {
    // nothing
    }

    // Destructor
    CGlobalCapturer::~CGlobalCapturer()
    {
    delete iWindowGroupName;
    delete iWindowGroup;
    iWsSession.Close();
    }

    // Cancel listening to key presses
    void CGlobalCapturer:oCancel()
    {
    iWindowGroup->CancelCaptureLongKey( iCaptureHandle );
    iWindowGroup->CancelCaptureKey( iCaptureHandle );
    }

    void CGlobalCapturer::StartCapturingL()
    {
    // Connect to the window server
    User::LeaveIfError( iWsSession.Connect() );
    // Create an invisible window group. Well, we'll make it invisible later
    /** @todo Can ELeave be used with R-classes? */
    iWindowGroup = new (ELeave) RWindowGroup ( iWsSession );
    // @see RBlankWindow::Construct
    iWindowGroup->Construct( (TUint32)iWindowGroup, EFalse );

    // You cannot just call CaptureLongKey for the same key code
    // You MUST call CaptureKey first
    User::LeaveIfError( iCaptureHandle = iWindowGroup->CaptureKey('5', 0, 0 ) );
    // And finally capture long key presses
    User::LeaveIfError( iLongCaptureHandle = iWindowGroup->CaptureLongKey('5','5', 0, 0, 0, 0 ) );
    // Send created window to the background and hide it from the
    // application switcher

    iWindowGroup->SetOrdinalPosition(-1);
    iWindowGroup->EnableReceiptOfFocus( EFalse );

    iWindowGroupName = CApaWindowGroupName::NewL( iWsSession );
    iWindowGroupName->SetHidden(ETrue);
    iWindowGroupName->SetWindowGroupName( *iWindowGroup );

    // Tell window server, that we are ready to receive events
    iWsSession.EventReady( &this->iStatus );
    CActiveScheduler::Add( this );
    SetActive();
    }

    // Key press happened
    void CGlobalCapturer::RunL()
    {
    if( iStatus == KErrNone )
    {
    // EEventKey received
    // console->Write( _L( "Captured key press\n" ) );
    TWsEvent we;
    iWsSession.GetEvent( we );

    if( we.Key()->iCode == KKeyCode )
    {
    if( we.Key()->iRepeats != 0 )
    myLogFile->WriteLog(_L8("Long key 5 pressed"));
    }
    else
    {
    // This should never happen, but just to demonstrate how
    // it is possible to forward events to the default destination
    TInt foregroundAppId = iWsSession.GetFocusWindowGroup();
    iWsSession.SendEventToWindowGroup( foregroundAppId, we );
    } // if iCode
    if( iCaptureCounter == KNumberOfPressesToCapture )
    {
    // exit MainL() inner loop
    CActiveScheduler::Stop();
    }
    else
    {
    iWsSession.EventReady( &iStatus );
    SetActive();
    } // if captured enough times
    } // if iStatus
    else
    {
    // Framework notified of some error
    /** @todo Handle error if required */
    }
    }

    //#ifdef __WINS__
    //EXPORT_C TInt WinsMain(TAny* /*aParam*/)
    // {
    // return Start();
    // }
    //#else
    GLDEF_C TInt E32Main()
    {
    return Start();
    }
    //#endif

    //GLDEF_C TInt E32Main()
    // {
    // // Create cleanup stack
    // __UHEAP_MARK;
    // CTrapCleanup* cleanup = CTrapCleanup::New();
    //
    // // Create output console
    // TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(
    // KConsFullScreen, KConsFullScreen)));
    // if (createError)
    // return createError;
    //
    // // Run application code inside TRAP harness, wait keypress when terminated
    // TRAPD(mainError, DoStartL());
    // if (mainError)
    // console->Printf(KTextFailed, mainError);
    // console->Printf(KTextPressAnyKey);
    // console->Getch();
    //
    // delete console;
    // delete cleanup;
    // __UHEAP_MARKEND;
    // return KErrNone;
    // }


    Thanks in advance.

    Rohanwaugh

Page 6 of 8 FirstFirst 12345678 LastLast

Similar Threads

  1. why program can not run in mobile phone ?
    By luohaibo in forum Symbian Tools & SDKs
    Replies: 9
    Last Post: 2009-03-05, 16:18
  2. Identify program running in background?
    By nire123 in forum Symbian C++
    Replies: 8
    Last Post: 2008-07-13, 07:50
  3. Can not run file manager program
    By agsapt in forum Symbian C++
    Replies: 0
    Last Post: 2002-08-27, 07:37
  4. i cannot run any java program in 9200 SDK
    By chili_fi in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2002-08-12, 23:34
  5. Run HandleSessionEventL() in background
    By chinazou305 in forum Symbian C++
    Replies: 0
    Last Post: 1970-01-01, 02:00

Posting Permissions

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