如何使用按键控制窗体上的按钮啊
我窗体上有上下左右来控制摄像头,我现在要用键盘的上下左右来触发窗体上的按钮,来实现相应的功能,不知道怎么实现,请教思路,谢谢
// .h
void __fastcall WndProc(TMessage& m);
// .cpp
void __fastcall TForm1::WndProc(TMessage& m)
{
switch (m.Msg)
{
case WM_KEYDOWN:
switch (m.WParam)
{
// 依次左上右下
case 37:
button1->Click();
break;
case 38:
button2->Click();
break;
case 39:
button3->Click();
break;
case 40:
button4->Click();
break;
}
break;
}
TForm::WndProc(m);
}
void __fastcall TForm1::ApplicationEvents1Message(tagMSG &Msg,
bool &Handled)
{
if (Msg.message == WM_KEYDOWN)
{
switch (Msg.wParam)
{
case VK_LEFT:
Caption = "左";
break;
case VK_UP:
Caption = "上";
break;
case VK_RIGHT:
Caption = "右";
break;
case VK_DOWN:
Caption = "下";
break;
default: break;
}
}
}