[Back To Directory]

Send A Keystroke:

1. Open Borland C++ Builder.
2. Place a Timer on Form1, set Enabled to false, set Interval to 3000.
3. Place a Label on the form.
4. Place a Button on the form.
6. Double click Button1.
7. Type the following red code in the Button1Click function:

//This what the Button1Click function should look like:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
   Timer1->Enabled = true;

   if(MessageBox(Application->Handle, "Whait for key stroke.", "Hello from MessageBox", MB_YESNO) ==IDYES)
   {
      Label1->Caption = "Y keystroke was sent";
   }
   else
   {
      Label1->Caption = "N keystroke was sent";
   }
}
//---------------------------------------------------------------------------


8. Double click Timer1.
9. Add the red code to the Timer1Timer function.

//This is what the timer Timer1Timer should look like:

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
   keybd_event('Y', 0, 0 ,0); //NOTE change Y to N to send the N keystroke
   Timer1->Enabled = false;
}
//---------------------------------------------------------------------------


10. Run the program. Click the button and in 3 seconds the keystroke will be sent to the forms message box.
NOTE: The keystroke is send to the window in the foreground only.





[Back To Directory]