Handling Input from the Keypad
Handling user input made by pressing keys on the phone's keypad is quite straightforward in the Symbian OS application framework. The application UI class should call CCoeAppUI::AddToStackL() when it creates an application view to ensure that keypad input is passed automatically to the current view. The key events can be inspected by overriding CCoeControl::OfferKeyEventL().
Note that only input from the numerical keypad and multi-way controller is passed into CCoeControl::OfferKeyEventL(). Input from the user's interaction with the menu bar, toolbar, or softkeys, is passed separately to the HandleCommandL() method of the application UI class for S60. In UIQ, the application view handles in-command input. This is because a command can be located on a softkey, in a toolbar, or in a menu, depending on the interaction style of the phone. To allow for this flexibility, commands are defined in a more abstract way, rather than being explicitly coded as particular GUI elements, such as menu items.
For either UI platform, the input event is handled according to the associated command, which is specified in the application's resource file. The Skeleton example demonstrates basic menu input handling in CSkeletonAppUi::HandleCommandL() for S60 and CSkele-tonUIQView::HandleCommandL() forUIQ.
In the Skeleton example, the handling of the user input is decoupled from the actual event, by storing it in a bitmask (iKeyState) when it is received, and handling it when the game loop next runs by inspecting iKeyState. This approach is shown in the simplified example code, for S60, below.
TKeyResponse CSkeletonAppView::OfferKeyEventL(const TKeyEvent&
aKeyEvent, TEventCode aType)
TKeyResponse response = EKeyWasConsumed;
TUint input = 0x00000000;
switch (aKeyEvent.iScanCode) {
case EStdKeyUpArrow: // 4-way controller up input = KControllerUp; // 0x00000001; breaks-
case EStdKeyDownArrow: // 4-way controller down input = KControllerDown; // 0x00000002; break;
case EStdKeyLeftArrow: // 4-way controller left input = KControllerLeft; // 0x00000004; break;
case EStdKeyRightArrow: // 4-way controller right input = KControllerRight; // 0x00000008; break;
case EStdKeyDevice3: // 4-way controller center input = KControllerCentre; // This is the "fire ammo" key
// Store the event, the loop will handle and clear it if (EEventKey == aType) {
default:
response = EKeyWasNotConsumed;// Keypress was not handled break;
if (EEventKeyDown == aType)
{// Store input to handle in the next update iKeyState | = input; // set bitmask
else if (EEventKeyUp == aType)
{// Clear the input iKeyState &= ^input; // clear bitmask
return (response);
TKeyEvent and TEventCode are passed in as parameters to Offer-KeyEventL(), and contain three important values for the key press - the event type, scan code, and character code for the key. Let's discuss these in some further detail.
Post a comment