Gambas Documentation
Como se hace...
Compilación e instalación
Componentes
gb
gb.cairo
gb.chart
gb.complex
gb.compress
gb.crypt
gb.db
gb.db.form
gb.desktop
gb.form
gb.form.dialog
gb.gui
gb.image
gb.net
gb.net.curl
gb.net.pop3
gb.net.smtp
gb.opengl
gb.qt4
.TextBox.Selection
_TreeView
Button
CheckBox
Color
ColumnView
ComboBox
Container
Control
Background
Cursor
DblClick
Delete
Design
Drag
Drag
DragMove
Drop
Drop
Enabled
Enter
Expand
Font
Foreground
GotFocus
Grab
H
Handle
Height
Hide
Hovered
Id
Ignore
Left
Lower
Menu
Mouse
MouseDrag
MouseMove
Move
MoveScaled
Name
Next
Parent
PopupMenu
Previous
Raise
Refresh
Reparent
Resize
ResizeScaled
ScreenX
ScreenY
SetFocus
Show
Tag
Tooltip
Top
Visible
W
Width
Window
X
Y
Cursor
Desktop
Dialog
DrawingArea
Form
Frame
GridView
HSplit
IconView
Image
Key
Label
ListBox
ListView
Menu
Message
MovieBox
Paint
PaintBrush
Panel
Picture
PictureBox
Printer
ProgressBar
RadioButton
ScrollBar
ScrollView
Separator
Slider
SpinBox
TabStrip
TextArea
TextBox
TextLabel
ToggleButton
ToolButton
trayicon
TreeView
UserContainer
Window
gb.qt4.ext
gb.settings
gb.xml
gb.xml.rpc
Controls pictures
Descripciones del Lenguaje
Developer Documentation
Documentacion y Recetas
Documentación del Entorno de Desarrollo
Fragmentos de código
Glosario
Índice del Lenguaje
LÉEME
Licencia del Wiki
Manual del Wiki
Mensajes de Error
Pendiente de traducción
Registrarse
Repositorio de Aplicaciones
Tutoriales
Últimos cambios

Event 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 class.

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 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.

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 event with STOP EVENT, the control won't see the keyboard event at all.

Warning, Care should be taken as some controls will swallow the keypress event.

This depends both on the control and the toolkit being used.