×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    2

    Receiving Key Events in an EXE

    I have created an EXE running in the background. I want to receive key events in that EXE. Can an EXE register for key event notifications?
    Last edited by SteveHough; 2004-06-07 at 12:15.

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    88
    You'll need to create a window server session,
    window group, optionally hide the window group,
    do a CaptureKey and then ask the server
    session for events. Like this:

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

    TRequestStatus status;

    RWindowGroup wg(ws);
    wg.Construct((TUint32)&wg, EFalse);
    CleanupClosePushL(wg);

    User::LeaveIfError(wg.CaptureKey(EKeyLeftArrow, 0, 0));

    ws.EventReady(&status);

    wg.SetOrdinalPosition(-1);
    wg.EnableReceiptOfFocus(EFalse);
    CApaWindowGroupName* wn=CApaWindowGroupName::NewLC(ws);
    wn->SetHidden(ETrue);
    wn->SetWindowGroupName(wg);
    for(;;) {
    User::WaitForAnyRequest();
    if (status.Int()==KErrNone) {
    TWsEvent e;
    ws.GetEvent(e);

    TInt c;
    TKeyEvent* aKeyEvent=e.Key();
    c=aKeyEvent->iCode;

    // do something with keypress
    }
    ws.EventReady(&status);

    // stop condition
    }
    ws.EventReadyCancel();
    CleanupStack::PopAndDestroy(3); //ws, wg, wn

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    2
    That's great! Thanks. Since posting the question I'd got as far as creating an RWindowGroup and capturing events and checking for key events. However, I hadn't figured how to hide the RWindowGroup from the running app / application list (as I hadn't found the class CApaWindowGroupName).

    I was deriving my CKeyWatcher from CActive and calling:
    iWinGroup.CaptureKeyUpAndDowns(EKeyToCapture, 0, 0);
    iWsSession.EventReady(&iStatus);
    SetActive();
    to request notifications. RunL was called when events were ready, and so in RunL I had the code:
    iWsSession.GetEvent(event);
    etc ...
    to get events and look for key events.

    A variation on the theme.
    Thanks again.

  4. #4
    Registered User
    Join Date
    Nov 2004
    Posts
    3
    hi,

    i'm facing with this problem too.i get Active Object
    in my exe.but when i want to connect to RWsSession
    it return "-1" error .i read this error occured when
    we try to reconnect to server.but its my first connecttion.
    i can connect to RWsSession in an app without any problem
    but in exe it return error.
    why???????

    can any body help me please????

    Regards

  5. #5
    Registered User
    Join Date
    Nov 2004
    Posts
    6

    User::WaitForAnyRequest();

    When i call this function in my CAppUi Class to capture key events
    it causes my application to crash.
    do any body the cause or solution.


    Best regards
    Ayyaz

  6. #6
    Registered User
    Join Date
    Dec 2004
    Location
    Switzerland
    Posts
    2

    What about sending instead of receiving?

    I would be interested in the reverse question of the OP, ie: how can I send a key event to an active application of my choice, or maybe less complicated, to the application that would get the keyboard input if I typed something?

Posting Permissions

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