×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Super Contributor
    Join Date
    Oct 2005
    Location
    Hyderabad,India
    Posts
    1,156

    RWsSession,SimulateKeyEvent doenst work as expected

    Hi all,

    Im trying to print some numbers which I have read, onto the screen. It works fine when its simulated on a notepad or on the message screen. But when I try it within the applications EDWIN only partial of the numbers appears.

    In detail this is what I have done:

    In .rss file:
    Code:
    RESOURCE EDWIN r_edwin_gtexted
        {
        flags =  EAknEditorFlagAllowEntersWithScrollDown ;
        width = 8;
        lines = 5;
        maxlength = 450;
        special_character_table = 0;
        avkon_flags = EAknEditorFlagNoT9;    
        }
    In my container I have constructed the Edwin:


    Code:
        TResourceReader reader;
        iCoeEnv->CreateResourceReaderLC( reader, R_EDWIN_GTEXTED );
        iGTextEd = new ( ELeave ) CEikEdwin;
        iGTextEd->ConstructFromResourceL( reader );
         CleanupStack::PopAndDestroy();  // Resource reader   
        iGTextEd->SetContainerWindowL( *this );
        iGTextEd->SetAknEditorFlags(EAknEditorFlagEnableScrollBars); 
        iGTextEd->SetObserver(this);   
        iGTextEd->SetExtent( GTEXTED_POS,iGTextEd->MinimumSize() );
        iGTextEd->SetAvkonWrap( ETrue );
        iGTextEd->SetAknEditorInputMode(EAknEditorNumericInputMode);
        iGTextEd->SetFocus( ETrue );
        iGTextEd->SetAvgCharsPerLine (10);
    
        iGTextEd->DrawNow();
        iGTextEd->ActivateL();  
        SetRect( aRect );
        ActivateL();
    And for simulating the key I invoked this function:


    Code:
    void CTextAppContainer5::InputText()
    {
         HBufC* iheap = HBufC::NewL(150);
         iheap->Des().Copy(_L("1112223333333444455566677788888999944444"));
    
    
         TPtr pbc= iheap->Des();                 
        pbc.Copy(iheap->Des());             
    
      //Windows server session variable
      RWsSession ws;
      User::LeaveIfError(ws.Connect());
      ws.SetBufferSizeL(100);
      ws.SetAutoFlush(ETrue);
    
    for(TInt i = 0; i < pbc.Length(); i++)                                  
    {
      TKeyEvent KeyEvent;
      KeyEvent.iCode = pbc[i];                                    
      KeyEvent.iModifiers = 0;
      KeyEvent.iRepeats = 0;
      KeyEvent.iScanCode = 0;
      ws.SimulateKeyEvent(KeyEvent);     //leftsoftkey/menu
      ws.Flush();      
    }
    ws.Close();
    delete iheap;
    I have also tried TRawEvent. But what ever I try it gets printed only “11122233333334444555666777888889”


    Thanks in advance,

    Regards,
    Priju

  2. #2
    Super Contributor
    Join Date
    Oct 2005
    Location
    Hyderabad,India
    Posts
    1,156

    Re: RWsSession,SimulateKeyEvent doenst work as expected

    Still stuck with the same!! Any hints guys!

    i was not sure whether its the problem with the editor construction or the RWsSession class.But RWsSession class prints out the entire buffer data on a notepad, hence it may not be the problem with this class.

    I also tried using Richtexteditor. but still the same issue. Only 29 characters are been printed. I dont understand whats that number related to.

    Is there any flags to be included while constructing the editor?

    Hope someone could provide me some hints on this.

    Thanks and Regards,
    Priju

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,740

    Re: RWsSession,SimulateKeyEvent doenst work as expected

    Seemingly the Window Server cannot handle arbitrary number of events at a time (note that however your code uses SetAutoFlush and Flush, it is a synchronous for-loop, thus your application does not consume events while you are generating them).
    Making things asynchronous fixes the problem:
    Code:
    // PrijuActive.h
    #ifndef __PRIJUACTIVE_H__
    #define __PRIJUACTIVE_H__
    
    #include <e32base.h>
    #include <w32std.h>
    
    class CPrijuActive : public CActive
    {
    public:
        static CPrijuActive* NewL();
        static CPrijuActive* NewLC();
        ~CPrijuActive();
    
        void DoCancel();
        void RunL();
    
    protected:
        CPrijuActive();
        void ConstructL();
    
    private:
        RWsSession iWs;
        TInt iIdx;
    };
    
    #endif
    Code:
    // PrijuActive.cpp
    
    #include "PrijuActive.h"
    
    CPrijuActive::CPrijuActive() : CActive(EPriorityStandard)
    {
    }
    
    CPrijuActive* CPrijuActive::NewL()
    {
        CPrijuActive* self = NewLC();
        CleanupStack::Pop();
        return self;
    }
    
    CPrijuActive* CPrijuActive::NewLC()
    {
        CPrijuActive* self = new(ELeave) CPrijuActive;
        CleanupStack::PushL(self);
        self->ConstructL();
        return self;
    }
    
    void CPrijuActive::ConstructL()
    {
        User::LeaveIfError(iWs.Connect());
        CActiveScheduler::Add(this);
        RunL();
    }
    
    CPrijuActive::~CPrijuActive()
    {
        iWs.Flush();
        iWs.Close();
    }
    
    void CPrijuActive::DoCancel()
    {
    }
    
    _LIT(KHello,"Hello World!qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM");
    
    void CPrijuActive::RunL()
    {
        if (iIdx<KHello().Length())
        {
            TKeyEvent KeyEvent;
            KeyEvent.iCode = KHello()[iIdx++];
            KeyEvent.iModifiers = 0;
            KeyEvent.iRepeats = 0;
            KeyEvent.iScanCode = 0;
            iWs.SimulateKeyEvent(KeyEvent);
            TRequestStatus *stat=&iStatus;
            User::RequestComplete(stat,KErrNone);
            SetActive();
        }
        else
            delete this;
    }
    (the code contains ugly stuff, I know)

    Example usage:
    Code:
    void CPrijuKeysAppUi::HandleCommandL(TInt aCommand)
    {
        switch (aCommand)
        {
        case EEikCmdExit:
        case EAknSoftkeyExit:
        case EAknSoftkeyBack:
            Exit();
            break;
    
        case EPrijuKeysCmd:
            CPrijuActive::NewL();
            break;
        }
    }

  4. #4
    Super Contributor
    Join Date
    Oct 2005
    Location
    Hyderabad,India
    Posts
    1,156

    Re: RWsSession,SimulateKeyEvent doenst work as expected

    Well Wizard,
    Let me first of all thank you for the reply.
    I did understand that the window server couldnt handle arbitary number of events. i tried giving a user::wait after each simulation of key event. But that didnt help me out.

    Let me try out what you have told and explained. I was behind this problem for days.

    Thanks you once again.I shall try it out and let you know.

    Regards

    Priju

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,740

    Re: RWsSession,SimulateKeyEvent doenst work as expected

    User::After does not break the synchronous loop, it just slows it down (so other parts of your code will not run).
    In case of Notepad or any other application the synchronous loop works because the other application runs in an other thread, thus it is able to consume events.

  6. #6
    Super Contributor
    Join Date
    Oct 2005
    Location
    Hyderabad,India
    Posts
    1,156

    Re: RWsSession,SimulateKeyEvent doenst work as expected

    Cool, I tried it out. Its pretty cool.
    Wizard, some of the codes are not clear to me here.

    Code:
            iWs.SimulateKeyEvent(KeyEvent);
            TRequestStatus *stat=&iStatus;
            User::RequestComplete(stat,KErrNone);
            SetActive();
    Here in RunL SimulateKeyEvent() is not an asynchronous function (which takes the parameter TRequestStatus.) But still we are taking the value of iStatus of CActive and completing the request using KErrNone and invoking RunL using SetActive(). So i guess this is a way to make Synchronous function to work as asynchronous.
    could you please ellaborate wizard

    Regards

    Priju

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,740

    Re: RWsSession,SimulateKeyEvent doenst work as expected

    Code:
    iWs.SimulateKeyEvent(KeyEvent);
    is unrelated, it is coming from your code.
    Code:
    TRequestStatus *stat=&iStatus;
    User::RequestComplete(stat,KErrNone);
    is self-triggering the active object. It could also be an RTimer::After with some low delay.
    Code:
    SetActive();
    should not be new I think.

    Note that the order of SetActive and issuing (in this case: completing) a request does not matter, since the Active Scheduler can check for completed Active Objects no sooner than our code returns (when both the SetActive and the RequestComplete will have been executed).

Similar Threads

  1. wmls files work on toolkit, but not on other emulators or on the server
    By Nokia_Archived in forum Browsing and Mark-ups
    Replies: 2
    Last Post: 2007-01-31, 10:22
  2. Why CAtive and RTimer not work in a thread?
    By hansoft in forum Symbian
    Replies: 8
    Last Post: 2005-02-09, 13:40
  3. Replies: 2
    Last Post: 2004-04-27, 10:36
  4. CommConnection does not work with Series 60 SDK, but works in JWT
    By jackiechan2001 in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2004-02-04, 09:07
  5. Does SDK v2.0 work on Series60 V6.1?
    By liying in forum Symbian Tools & SDKs
    Replies: 3
    Last Post: 2004-02-02, 08: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
  •  
×