Event Control.KeyPress (gb.qt4)
Event KeyPress ( )
当控件有焦点时有按键按下,发生该事件。
用
Key类可以获取按下的按键信息。
KeyPress例程结束后,
TextBox控件内部的文本被Gambas根据按键编辑。所以它不检测从KeyPress 事件处理程序及其调用的任何子程序和函数中写回进Text 属性的任何信息。而Change事件开始于内容更新之后。
Examples
PUBLIC SUB n_Keypress()
'事件处理对于组 n - 这是9X9的TextBoxe数组
DIM ltext AS Variant
DIM ltag AS Variant
ltext = Key.Text ' 获取键代码
ltag = LAST.Tag ' 组属性
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) ' 转换字符串为整数,并保存在整数数组中
...
' 不必像这样更新域: 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.