×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    413

    How to capture long 5 key press in console application running in background?

    hi all,

    i have developed GUI application in which my application running in background is detecting a long key press for key '5'.I have used active object and observer class in that code.Now i want to do same in console application.Is it must to use active object in console application ??

    i don know much about console application.Anybody has any idea as to how to do it??

    Thanks in advance.

    ROhanwaugh.

  2. #2
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    413

    Re: How to capture long 5 key press in console application running in background?

    hi all,

    i am attaching my .cpp file here in which i haven't used active object,but it is detecting only single key press not long key press.


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

    // Include Files

    #include "ConsoleKeyCapture.h"
    #include <e32base.h>
    #include <e32std.h>
    #include <e32cons.h> // Console
    #include <W32STD.h>
    #include <APGWGNAM.H>
    // Constants

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

    // Global Variables

    LOCAL_D CConsoleBase* console; // write all messages to this


    // Local Functions

    void CaptureKey()
    {

    RWsSession ws;
    User::LeaveIfError(ws.Connect());
    CleanupClosePushL(ws);

    TRequestStatus status;

    // create a window group for the thread
    RWindowGroup wg(ws);
    wg.Construct((TUint32)&wg, EFalse);
    CleanupClosePushL(wg);

    // capture a key
    User::LeaveIfError(wg.CaptureKey('5',0,0));
    User::LeaveIfError(wg.CaptureLongKey('5','5',0,0,0,ELongCaptureNormal));


    // listen for the key presses[[Category:Connectivity]]
    ws.EventReady(&status);

    // hide this window group from the app switcher
    wg.SetOrdinalPosition(-1);
    wg.EnableReceiptOfFocus(EFalse);
    CApaWindowGroupName* wn=CApaWindowGroupName::NewLC(ws);
    wn->SetHidden(ETrue);
    wn->SetWindowGroupName(wg);

    // handle key events
    for(;
    {
    User::WaitForAnyRequest();
    if (status.Int()==KErrNone)
    {
    TWsEvent e;
    ws.GetEvent(e);

    TInt c;
    TKeyEvent* aKeyEvent=e.Key();//[[Category:UI]]
    c=aKeyEvent->iCode;
    console->Write(_L("5 key press is detected!\n"));

    // do something with keypress

    // if not ours, then send to top window group
    // note that this breaks key repeat
    TInt wgid=ws.GetFocusWindowGroup();
    ws.SendEventToWindowGroup(wgid, e);
    }
    ws.EventReady(&status);

    // stop condition
    }

    // clean up
    ws.EventReadyCancel();
    CleanupStack::PopAndDestroy(3); //ws, wg, wn
    }






    LOCAL_C void MainL()
    {
    //
    // add your program code here, example code below
    //


    CaptureKey();
    }

    LOCAL_C void DoStartL()
    {
    // Create active scheduler (to run active objects)
    CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
    CleanupStack::PushL(scheduler);
    CActiveScheduler::Install(scheduler);

    MainL();

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

    // Global Functions

    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.regards.

    Rohanwaugh.

  3. #3
    Registered User
    Join Date
    Jul 2012
    Posts
    22

    Re: How to capture long 5 key press in console application running in background?

    Quote Originally Posted by rohanwaugh View Post
    hi all,

    i have developed GUI application in which my application running in background is detecting a long key press for key '5'.I have used active object and observer class in that code.Now i want to do same in console application.Is it must to use active object in console application ??

    i don know much about console application.Anybody has any idea as to how to do it??

    Thanks in advance.

    ROhanwaugh.

    Hi Rohan,

    I am trying to develop a GUI app which should be able to capture long press key event in background.
    Can u please elaborate how you did the same in your app.
    If you could provide code snippets, that would be more helpful.

    Thanks in advance.

    - Akshay

Similar Threads

  1. capture short key and long key
    By kkrish in forum Symbian
    Replies: 4
    Last Post: 2010-02-09, 04:48
  2. Replies: 1
    Last Post: 2008-09-19, 03:45
  3. Console application not running on Nokia 6210 Navigator and Nokia E61
    By rohanwaugh in forum Symbian User Interface
    Replies: 22
    Last Post: 2008-09-13, 10:31
  4. Replies: 0
    Last Post: 2007-11-27, 11:09
  5. Replies: 5
    Last Post: 2006-12-22, 07:32

Posting Permissions

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