/*
KeyPreview, OnKeyDown, OnKeyUp example
This cross-platform example changes a form’s color to aqua when the user presses the F1 key, even when a control on the form has the focus. When the user releases the key, the form returns to its original color.
*/
TColor FormColor;
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  KeyPreview = true;
}

void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
  if (Key == Key_F1)
  {
    FormColor = Form1->Color;
    Form1->Color = clAqua;
  }
}
void __fastcall TForm1::FormKeyUp(TObject *Sender, WORD &Key, TShiftState Shift)
{
  if (Key == Key_F1)
    Form1->Color = FormColor;
}
 
