Reference for the Mosaic class Core::KeyEvent

Core::KeyEvent
CharCode
Code
Down
Initialize()
Initialize2()
IsCode()
Core::Event
IsTimeExact
Time
GetCurrentTime()

The class Core::KeyEvent provides a specialized event object able to deliver key pressure and release events. Each time a key event occurs, the code of the pressed or released key will be passed in the Core::KeyEvent object to the application. On its part the application dispatches the event to the GUI components along the focus path. See the method DispatchEvent() of the class Core::Group.

The Mosaic framework defines a fixed set of the most important key codes (Menu, Left, Up, Ok, Exit, Play, Record, etc.). The usage of these predefined key codes increases the platform independence of your GUI application. For special key codes, which are not included in this set, a range of UserXX key codes is provided. The codes are defined in the enum Core::KeyCode.

Beside the predefined fixed set of key codes the Core::KeyEvent object can also deliver a UNICODE character codes. This is very useful if your target device supports an alpha numerical keyboard.

Usually the key codes and the character codes are used exclusively in the Core::KeyEvent object. If an event contains a valid key code (Menu, Left, Ok, etc.), the character code is set to '\x0000'. In the case, a character code is passed in the event, the key code is set to NoKey. Digits, alpha signs 'A' .. 'Z' and some few special signs like '+', '-', '*' are handled in a special manner, they are passed as well as key codes Key0 .. Key9, KeyA .. KeyZ, KeyPlus, KeyMinus, KeyMultiply and as character codes '0' .. '9', 'A' .. 'Z', '+', '-', '*'.

var char CharCode;

The variable 'CharCode' stores the UNICODE character code of the pressed or released character. For key codes the variable is initialized with '\x0000' and the key code is stored in the variable Code.

var Core::KeyCode Code;

The variable 'Code' stores the code of the pressed or released key. For UNICODE characters the character code is stored in the CharCode variable and the variable Code is initialized with the value Core::KeyCode.NoKey.

var bool Down;

The variable 'Down' determines whether the key has been pressed (Down == true) or released (Down == false). For target devices, which are not able to detect the key release, the key release events may be omitted..

method Core::KeyEvent Initialize
(
arg Core::KeyCode aCode,
arg bool aDown
);

The method Initialize() initializes this Core::KeyEvent object with the given parameters. This method stores the key code aCode in the variable Code and returns this event object to the caller. The CharCode variable will be initialized with the zero character '\x0000' unless a Key0 .. Key9; KeyA .. KeyZ code is passed to this method. In this case the variable CharCode is initialized with the corresponding UNICODE character code '0' .. '9' or 'A' .. 'Z'.

method Core::KeyEvent Initialize2
(
arg char aCode,
arg bool aDown
);

The method Initialize2() initializes this Core::KeyEvent object with the given parameters. This method stores the UNICODE character code aCode in the variable CharCode and returns this event object to the caller. The Code variable will be initialized with the Core::KeyCode.NoKey value unless a '0' .. '9', 'A' .. 'Z' character code is passed to this method. In this case the variable Code is initialized with the corresponding key code Key0 .. Key9 or KeyA .. KeyZ.

method bool IsCode
(
arg Core::KeyCode aCodeOrCategory
);

The method IsCode() compares the key code stored within the event with the code passed in the parameter aCodeOrCategory and returns 'true' or 'false' depending on the result of this operation.

The method is able to test whether a code does belong to a code category. Categories are special codes defined in the Core::KeyCode enumeration, like AlphaKeys, DigitKeys or CursorKeys. They stand for an entire range of key codes.