Home > Products > SophiaFramework UNIVERSE > Tutorial > Breakout > - 7 / 9 -

BREW Breakout - 7 / 9 -

Key Event Processing

Key event processing is done by the OnKey handler function.

Processes corresponding to each key are different according to application status in this game, but here are the basics.

// Key handler
Bool Block::OnKey(UInt16 key)
{
  // Processing when a key is pressed
  ...
    switch(key) {
      case AVK_4:
      case AVK_LEFT:
        if (_racket.racket.GetLeft() > _gameArea.GetLeft()) {
          _racket.velocity.Set(-_racketSpeed, 0);
        }
        break;
      case AVK_5:
      case AVK_SELECT:
        _racket.velocity.Set(0, 0);
        break;
      case AVK_6:
      case AVK_RIGHT:
        if (_racket.racket.GetRight() < _gameArea.GetRight()) {
          _racket.velocity.Set(_racketSpeed, 0);
        }
        break;
      default:
        break;
    }
    return true;
  ...
  return false;
}

The pressed key's event code is saved in the variable key, and appropriate processing is done according to its value. For table of correspondence between actual key and key code, please refer to "BREW API reference" - "Key codes".

TRUE is returned when a key event is handled, and FALSE is returned when a key event is ignored. Ignored key events will be processed by BREW.

Go back  1   2   3   4   5   6   7   8   Apdx   Next page