Home > comp > gb.qt > control > .keypress 
  [3.0]
 fr de es it nl pl pt pt_BR mk sq ca ar fa vi ja ru zh zh_TW eo
Previous  Next  Edit  Rename  Undo  Refresh  Search  Administration  
Documentation
History
 
Control.KeyPress (gb.qt)
Syntax
EVENT KeyPress ( )
Raised when a key is pressed while the control has the focus.

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

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

Examples


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 code

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