<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../../../style.css">
<title>
Gambas Documentation - Control.KeyPress
 (gb.qt)</title>
</head>
<table class="none" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td align="left">
<font size="-1">
<a href="../../../../help+en"><img class="flag" alt="Home" border="0" src="../../../../img/lang/en.png" align="center"></a>&nbsp;
<a href="../control+en">Up</a>&nbsp;
<a href="_gotfocus+en">Previous</a>&nbsp;
<a href="_keyrelease+en">Next</a>&nbsp;
</td></tr></table>
<div class="notab">
<h1>
Control.KeyPress
 (gb.qt)</h1>
<div class="black"><font size="-2"><b>Syntax</b></font></div>
<pre class="syntax"><font color="blue">EVENT</font> <b>KeyPress</b> <font color="blue">(</font> <font color="blue">)</font></pre>
Raised when a key is pressed while the control has the focus.
<p>
You get information about the pressed key with the <a href="../key+en">Key</a> class.
<p>

After the KeyPress routine has finished, the Text inside the <a href="../textbox+en">TextBox</a>
is edited by <a href="../../../def/gambas+en">Gambas</a>, 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.
<p>
<div class="gray"><font size="-2"><b>Example</b></font></div>
<pre class="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 code

ltag = LAST.Tag ' The Group Property
IF NOT IsNull(ltext) THEN
  IF Mid(ltext, 1) &gt;= &quot;0&quot; AND Mid(ltext, 1) &lt;= &quot;9&quot; 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</pre>

</div>
</body>
</html>

