Principal > comp > gb.qt4 > control > .keypress 
 en fr de it nl pl pt pt_BR mk sq ca hu cs tr ar fa id vi ko ja ru zh zh_TW eo
Previo  Siguiente  Editar  Renombrar  Deshacer  Buscar  Administración  
Documentación  
¡Precaución! La página no está traducida.  Véase la versión inglesa 
Control.KeyPress (gb.qt4)
Event KeyPress ( )

Raised when a key is pressed while the control has the focus.

You get information about the pressed key with the Key clase.

After the KeyPress routine has finished, the Text inside a TextBox is edited by Gambas, according to the key. So it makes no sense to write back into the Text propiedad any information from the KeyPress evento handler, nor from any of the subroutines and functions it calls. Rather use the Change event, which comes after updating the content.

Example

PUBLIC SUB n_Keypress()
' Event handler for the Group n - this is the 9 by 9 array of TextBoxes
DIM ltext AS Variant
DIM ltag AS Variant


ltext = Key.Text ' Get the key text

ltag = LAST.Tag ' The Group Property
IF NOT IsNull(ltext) THEN
  IF Mid(ltext, 1) >= "0" AND Mid(ltext, 1) <= "9" THEN
    ' Has pressed one of the numeric keys 0 to 9
    z[ltag] = Int(Asc(ltext) - 48) ' convert string to integer and save in integer array
...

' must not update the field as e.g.: n.Text = 48 + i

Event Cancellation

If you stop the evento with STOP EVENT, the control won't see the keyboard event at all.