11.2. Derivados de TwinControl
OnKeyDown
Ocurre cuando el usuario oprime una tecla y el control tiene el foco. Este evento responde a todas las teclas, cualquier tecla alfanumérica, incluso las teclas de función combinadas con Shift y Alt, las teclas de control (Ctrl), y los botones del ratón pulsados.
typedef void __fastcall (__closure *TKeyEvent)(System::TObject* Sender, Word &Key, Classes::TShiftState Shift);
__property TKeyEvent OnKeyDown = {read=FOnKeyDown, write=FOnKeyDown};
La variable Shift entrega un parámetro que indica que tecla de control (Shift, Alt, Ctrl) está combinada con la tecla pulsada ( valor de Key).
State | Meaning |
ssShift | The Shift key is held down. |
ssAlt | The Alt key is held down. |
ssCtrl | The Ctrl key is held down. |
The following code aborts a print job if the user presses Esc. Note that you should set KeyPreview to True to ensure that the OnKeyDown event handler of Form1 is called.
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
if (Key == VK_ESCAPE && Printer()->Printing)
{
Printer()->Abort();
MessageDlg("Printing aborted", mtInformation, TMsgDlgButtons() << mbOK,0);
}
}
OnKeyPress
Ocurre cuando se pulsa una tecla alfanumérica, o a las teclas Tab, Retroceso, Entrar y Esc.
typedef void __fastcall (__closure *TKeyPressEvent)(System::TObject* Sender, char &Key);
__property TKeyPressEvent OnKeyPress = {read=FOnKeyPress, write=FOnKeyPress};
This event handler displays a message dialog box specifying which key was pressed:
void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key)
{
char keyString[25];
KeyString[0] = Key;
strcpy(&keyString[1], " Was Pressed");
Application->MessageBox(keyString , "Key Press", MB_OK);
}
OnKeyUp
Tiene lugar cuando se suelta cualquier tecla que está oprimida. Este evento responde a todas las teclas, cualquier tecla alfanumérica, incluso las teclas de función combinadas con Shift y Alt, las teclas de control (Ctrl), y los botones del ratón pulsados.
typedef void __fastcall (__closure *TKeyEvent)(System::TObject* Sender, Word &Key, Classes::TShiftState Shift);
__property TKeyEvent OnKeyUp = {read=FOnKeyUp, write=FOnKeyUp};
La variable Shift entrega un parámetro que indica que tecla de control (Shift, Alt, Ctrl) está combinada con la tecla pulsada ( valor de Key).
State | Meaning |
ssShift | The Shift key is held down. |
ssAlt | The Alt key is held down. |
ssCtrl | The Ctrl key is held down. |