Link to home
Start Free TrialLog in
Avatar of TropicalFish
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(TCMWantSpecialKey &Message);

  BEGIN_MESSAGE_MAP
     MESSAGE_HANDLER(CM_WANTSPECIALKEY , 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(TCMWantSpecialKey &Message)
{
  if(Message.CharCode != VK_TAB)
     TForm::Dispatch((void*)&Message);
  else Message.Result = 1;
}
....  
Avatar of thienpnguyen
thienpnguyen

Avatar of TropicalFish

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
Avatar of thienpnguyen
thienpnguyen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try to press "Tab" ==> caption wil change to "Tab Key Down ...."
press other key   ==> caption will come back to "Form1"
Great!! And it works for releasing the Tab key too!
Thanks a lot!