Datasheet

HANDLING INPUT FROM THE KEYPAD 51
2. EEventKey generated after the key down event, and then regularly
as long as the key is kept down
2
3. EEventKeyUp generated when the key is released.
The EEventKeyDown and EEventKeyUp pair of events can be used
to set a flag in the game to indicate that a particular key is being held, and
then clear it when it is released, as shown in the previous example. Using
this technique, the state of the relevant input keys is stored, and key repeat
information can be ignored (the repeated input notification often does
not work well for games, because it results in jerky motion, for example,
when a user holds down a key to drive a car forward in one direction).
However, it can be useful in other contexts. Since the EEventKey event
is passed repeatedly if a key is held down, it can be used for repeating
events, such as firing ammunition every quarter second while a particular
key is held down. This is much easier and more comfortable for the player
than needing to repeatedly press the key. The
Skeleton
example code,
shown above, illustrates this each time a repeat event is received from
holding down the centre key of the 4-way controller.
2.4.2 Key Codes
Either the scan code or the character code can be used by the game to
determine which key has been pressed. The scan code (TKeyEvent::
iScanCode) simply provides information about the physical key pressed,
which is usually sufficient for processing events in games, since all that
is required is information about the direction or the keypad number
pressed. The character code may change when, for example, a single
key is pressed multiple times, depending on how the mappings and any
front end processors are set up. This level of detail isn’t often needed by
a game, so the character code is generally ignored.
A game must also be able to handle the case where two or more keys
are pressed simultaneously, for example, to simulate 8-way directional
control or allow for more complicated key sequences and controls. The
Skeleton
example does this by storing input in a bitmask, so multiple
simultaneous key presses can be handled together by the loop.
By default, pressing multiple keys simultaneously is not possible;
the event from the first key to be pressed is received and others are
discarded while it is held down. This is called key blocking. However,
the application UI can call CAknAppUi::SetKeyBlockMode() on
2
RWsSession::GetKeyboardRepeatRate() can be used to determine the repeat
interval and it can be modified by calling RWsSession::SetKeyboardRepeatRate().