User Tools

Site Tools


k14:k14.1:k14.1.1:start

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 KeyDescription
AltReturns True if ALT key is pressed
ControlReturns True if the Control key has been pressed
ShiftReturns True if the SHIFT key is pressed
NormalReturns True if no special key was pressed
MetaReturns True if the Meta or Super key has been pressed
CodeReturns the code of the key
TextReturns 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"]
'...
The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k14/k14.1/k14.1.1/start.txt · Last modified: 11.02.2022 (external edit)

Page Tools