Symbian
Symbian OS Library

FAQ-1154 How can I receive key events in my application?

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



 

Classification: C++ Category: Applications
Created: 10/13/2004 Modified: 11/12/2004
Number: FAQ-1154
Platform: Not Applicable

Question:
How can I receive key events in my application? How is the situation different between controls and the app UI class itself?

Answer:
Key mapping

Symbian OS maps keys from the hardware to specfic keys on a given device. The generic device-specific keys are defined in e32keys.h. These are then aliased to device-specific keys e.g. for UIQ in QuartzKeys.h.

Handling key events in a view i.e. CCoeControl

You can handle a key event in your view control by overidding the OfferKeyEventL(...) method. Note that you need to return the correct TKeyResponse value to avoid consuming a key not destined for your app. See How To Get User Events on receiving this and other events in your application

Handling key events in the Application UI class

To handle a key in your UI class you need to override the HandleKeyEventL(...) and handle the keys the same way as in your view. Note that both the UI and the active view will receive a key event notification, the UI object receiving the notification first.

Can I receive UI commands from a Menubar directly in my view ?

You cannot directly receive commands in your view from either a Menubar or a Toolbar, even if the view is currently active. This is because the UI owns these components and it's the UI object that receives the commands from the system directly. To handle a command in your view you need to channel/divert these commands from the HandleCommandL(...) method of your UI to the desired view object. See the end of Application development tutorial » The application GUI for more information.