[Back To Directory]

Display The ASCII Value and Character of a pressed key.:

1. Open Borland C++ Builder.
2. Place a Label on Form1.
3. Place another Label on Form1.
4. Select Form1 and go to the Object Inspector and add the function KeyUp.
5. Type the following red code in the FormKeyUp function:

//This is what the FormKeyUp function should look like:

void __fastcall TForm1::FormKeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
   AnsiString asciiValue = "The ASCII value of the key pressed is: ";

   asciiValue += Key;
   Label1->Caption = asciiValue;
}
//---------------------------------------------------------------------------


6. Select Form1 go to the Object Inspector and add the function KeyPress.

//This is what the FormKeyPress function should look like:

void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key)
{
   AnsiString CharValue = "The ASCII value of the key pressed is: ";

   CharValue += Key;
   Label2->Caption = CharValue;
}
//---------------------------------------------------------------------------


7. Run the program. Press any keys and the value of the key pressed will be displayed..



[Back To Directory]