Symbian
Symbian OS Library

FAQ-0791 How do I simulate a key press?

[Index][spacer] [Previous] [Next]



 

Classification: C++ Category: Window Server
Created: 05/09/2002 Modified: 05/10/2002
Number: FAQ-0791
Platform: Symbian OS v6.0, Symbian OS v6.1

Question:
I am writing a test driver for my application and I want to simulate the sending of key presses to the window server. How do I do this?

Answer:
You can use the SimulateKeyEvent(TKeyEvent) method of RWsSession as follows. There is a corresponding SimulateRawEvent(TRawEvent) if you want to generate scan codes. The latter also works under v5 of Symbian OS - see FAQ-0292.

    RWsSession& wsSession=iCoeEnv->WsSession();
    TKeyEvent keyEvent;
    keyEvent.iCode = EKeyPageDown; // member of TKeyCode
    keyEvent.iScanCode = EKeyPageDown;
    keyEvent.iModifiers = 0;
    keyEvent.iRepeats = 0;
    wsSession.SimulateKeyEvent(keyEvent);
    wsSession.Flush();