//=========================================================================== // KEYPRESS EXAMPLES // Set the KeyPreview property of Form1 to "true" //=========================================================================== //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- //=========================================================================== // EVENT HANDLERS //=========================================================================== //------------------------------------------------------------------ Key Down void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { Form1->EditKeyDown->Text = Key; if (Key == 186) Form1->Color = clFuchsia; // 186 is the :; key // Key is a 16-bit unsigned integer // Key CANNOT distinguish the shift state of a key // BUT, Edit->Text displays BOTH the shift-dependent character // AND the shift-independent value } //----------------------------------------------------------------- Key Press void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key) { Form1->EditKeyPress->Text = Key; if (Key == '+') Form1->Color = clLime; if (Key == '=') Form1->Color = clYellow; // Key is a char // Key DOES distinguish the shift state of a key // Edit->Text displays ONLY the shift-dependent character } //-------------------------------------------------------------------- Key Up void __fastcall TForm1::FormKeyUp(TObject *Sender, WORD &Key, TShiftState Shift) { Form1->EditKeyUp->Text = Key; if (Key == 186) Form1->Color = clAqua; // 186 is the :; key // Key is a 16-bit unsigned integer // Key CANNOT distinguish the shift state of a key // Edit->Text displays ONLY the shift-independent value } //---------------------------------------------------------------------------