Table of Contents
14.1.1 Class Key
The (static) Key class (gb. qt4) is used to retrieve information from the keyboard and defines constants for selected keys. Apart from the properties, this class has no methods.
Similar to the class Mouse (→ chapter 14.2), the class Key does not have any events itself, but there are keyboard events that are dealt with in → chapter 14.1.3.
14.1.1.1 Properties of the class Key
The following table presents selected properties of the Key class:
| Property Key | Description |
|---|---|
| Alt | Returns True if ALT key is pressed |
| Control | Returns True if the Control key has been pressed |
| Shift | Returns True if the SHIFT key is pressed |
| Normal | Returns True if no special key was pressed |
| Meta | Returns True if the Meta or Super key has been pressed |
| Code | Returns the code of the key |
| Text | Returns the text assigned to the key as a character. |
Table 14.1.1.1.1: Description of selected properties of the 'Key' class
Please note that, for example, the properties Key. Alt, Key. Control, Key. Shift and Key. Normal are always associated with the two events Component_KeyPress or Component_KeyRelease!
14.1.1.2 Keys - Constants
Gambas has a set of keyboard constants for certain keys with sufficient self-explanatory names:
F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 Enter Return Left Right Down Up Home End PageUp Insert PageDown Delete BackSpace Space Tab NumLock CapsLock Esc Pause Print
Observe these notes:
- Never use the key values directly because they change between GUI components, but always use the constants in this notation: Key.Constant!
- Never use the numeric ASCII values or the Asc() function to test for letters, but always use the Array function of the Key class:
'... Dim iKeyValue As Integer ' Syntax: anInteger = Key[ Key As String ] iKeyValue = Key["R"] '...
