Главная страница | назад





Article #17365: Arrow keys handler

 Question and Answer Database
FAQ2365C.txt Arrow keys handler
Category :VCL
Platform :All
Product :C++Builder 3.x
Question:
I need to intercept the arrow keys like VK_RIGHT.
FormKeyPress() gets called on F1,Crtl,Alt,PgUp,
but never called on the arrow keys.
Answer:
You need to handle that at the application level. A handler for
Application->OnMessage will do it. Here's an example for VK_UP and VK_DOWN,
I'm sure you can extrapolate. Be sure an put the prototype for
void __fastcall TFrmArrows::AppMessage(TMsg& AMessage, bool& Handled)
in the Form's class declaration in the header file:
void __fastcall TFrmArrows::AppMessage(TMsg& AMessage, bool& Handled)
{
if (AMessage.message == WM_KEYDOWN)
if ((AMessage.wParam == VK_UP)
|| (AMessage.wParam == VK_DOWN)) {
SelectNext(ActiveControl, (AMessage.wParam == VK_DOWN), true);
Handled = true;
}
}
void __fastcall TFrmArrows::FormCreate(TObject *Sender)
{
Application->OnMessage = AppMessage;
}
//---------------------------------------------------------------------------
7/2/98 10:32:32 AM

Last Modified: 01-SEP-99