03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

� I don't have to 'consume' the key. I return a value (EKeyWas-Consumed or<br />

EKeyWasNotConsumed) to indicate whether I consumed it.<br />

The function starts by determining the kind of key event. There are three possibilities –<br />

hardware key down, standard key, or hardware key up. Here, I'm only interested in standard<br />

key events indicated by the value EEventKey being passed in the second parameter of the<br />

function. I can handle the key in one of the three ways:<br />

� I can ignore it if it's not a key that I recognize or want to use at this time.<br />

� I can handle it entirely internally, within the control, by (say) moving the cursor, or (if it<br />

were a numeric editor) changing the internal value and visual representation of the<br />

number being edited by the control.<br />

� I can generate some kind of command that will be handled outside the control, like the<br />

hit-fleet command that's generated when I press the Confirm key when on a new tile, or<br />

(if this were a choice list item in a dialog) an event saying that the value displayed in the<br />

choice list had been changed.<br />

For issuing commands from COppFleetView, I call<br />

iData.iCmdHandler.ViewCmdHitFleet(), specifying the coordinates of the tile to hit.<br />

iCmdHandler is of type MGameViewCmdHandler&, an interface class that I implement in<br />

CGameController. I'll show the definition of the interface below.<br />

Those are the main issues in key event handling. But you also need to know some of the<br />

details about how to crack key events and key codes. The first parameter to<br />

OfferKeyEventL() is of type TKeyEvent&, a reference to a window server key event<br />

that's defined in w32std.h:<br />

struct TKeyEvent<br />

{<br />

TUint iCode;<br />

TInt iScanCode;<br />

TUint iModifiers; // State of modifier keys and pointing device<br />

TInt iRepeats; // Count of auto repeats generated<br />

};<br />

The legal values for iCode, iScanCode, and iModifiers are in e32keys.h.<br />

� Use values from the TKeyCode enumeration to interpret iCode. The values are<br />

=0xf800 for the usual function, arrow, menu, and other keys found on<br />

PC keyboards. Although Symbian OS phones may have no keyboard, many of these<br />

key events may still be generated using a front end processor (FEP).<br />

� Use TStdScanCode and iScanCode for the extremely rare cases when scan codes<br />

are of interest. The scan codes are defined by the historical evolution of IBM PC<br />

keyboards since 1981. They originally represented the physical position of a key on the<br />

81-key IBM PC keyboard, and have evolved since then to support new keyboards and<br />

preserve compatibility with older ones. Since keyboards and keypads used on Symbian<br />

OS phones are rather different, scan codes have limited value.<br />

� Use TEventModifier to interpret the bits in iModifiers. This enables you to test<br />

explicitly for Shift, Ctrl, and other modifier keys, where supported. These are of<br />

particular interest in combination with navigation keys.<br />

UIQ defines some additional key codes in quartzkeys.h. These represent the events<br />

generated by the two or four direction keys on the keypad, and the Confirm key – they are<br />

the key events that are consumed by COppFleetView::OfferKeyEventL(), above.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!