我是这样做的:
在Form1的KeyPress事件中:
void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key)
{
if(Key==VK_F1)
ShowMessage("aa");
}
可运行时按F1却没出现消息框,我试了Key==112和Key==0x70都不行,F2-F12也都不行,只有Key等于回车时行,为什么?不知是不是BC的bug?
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key == VK_F1)
ShowMessage("aa");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
KeyPreview = true;
}
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key == VK_F1)
ShowMessage("aa");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
this->KeyPreview = true;
}
没有问题,无论焦点在不再Form上,都可以弹出消息!
要在keydown里写,bcb是不会出这样的bug的