TropicalFish
asked on
Tab with OnKeyDown and OnKeyUp
I have an empty form without any components on it. I use the OnKeyDown event to respond to keyboard events. It works for all keys I need it for but the Tab key.
I recently upgraded from BCB4 to BCB5. In BCB4 I used the following code, but it gives an error in BCB5. Anyways I couldn't catch the tab KeyUp with it, so how can I catch both those events in BCB5?
Thanks
//Code used in BCB4:
....
The .h
void __fastcall KeyDown(Word &Key, Classes::TShiftState Shift);
void __fastcall CMWantSpecialKey(TCMWantSp ecialKey &Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(CM_WANTSPE CIALKEY , TCMWantSpecialKey, CMWantSpecialKey)
END_MESSAGE_MAP(TForm)// Assumes this is in a form derived from TForm
The .cpp
void __fastcall TForm1::KeyDown(Word &Key, Classes::TShiftState Shift)
{
if (Key == VK_TAB)
// do something
TForm::KeyDown(Key,Shift);
}
//------------------------ ---------- ---------- ---------- -
void __fastcall TForm1::CMWantSpecialKey(T CMWantSpec ialKey &Message)
{
if(Message.CharCode != VK_TAB)
TForm::Dispatch((void*)&Me ssage);
else Message.Result = 1;
}
....
I recently upgraded from BCB4 to BCB5. In BCB4 I used the following code, but it gives an error in BCB5. Anyways I couldn't catch the tab KeyUp with it, so how can I catch both those events in BCB5?
Thanks
//Code used in BCB4:
....
The .h
void __fastcall KeyDown(Word &Key, Classes::TShiftState Shift);
void __fastcall CMWantSpecialKey(TCMWantSp
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(CM_WANTSPE
END_MESSAGE_MAP(TForm)// Assumes this is in a form derived from TForm
The .cpp
void __fastcall TForm1::KeyDown(Word &Key, Classes::TShiftState Shift)
{
if (Key == VK_TAB)
// do something
TForm::KeyDown(Key,Shift);
}
//------------------------
void __fastcall TForm1::CMWantSpecialKey(T
{
if(Message.CharCode != VK_TAB)
TForm::Dispatch((void*)&Me
else Message.Result = 1;
}
....
http://bcbdev.com/faqs/faq78.htm
ASKER
I've read that, but as the note on the bottom of that page sais, it doesn't work that way on empty forms without controls...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try to press "Tab" ==> caption wil change to "Tab Key Down ...."
press other key ==> caption will come back to "Form1"
press other key ==> caption will come back to "Form1"
ASKER
Great!! And it works for releasing the Tab key too!
Thanks a lot!
Thanks a lot!