OnKeyDown event for TAB

First of all: a happy new year 2000...

Normally, TAB key shifts focus from a wincontrol to another on my active form.But I want TAB to do something different...
So,it would be great to get any notifying about a pressed TAB key on the active form before the focus shifting mechanism could take place.
Unfortunately the focused control does not receive onkeydown messages when TAB is pressed unless the control’s wanttabs property is defined and its value is true.
 Thanks,
Zoltan
zoltan082098Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

EpsylonCommented:
Happy new year to u 2!!!

Set TForm.KeyPreview to true and use OnKeyDown and OnKeyUp to intercept VK_TAB...
0
EpsylonCommented:
Hmmm.... I see that Tab, BackTab, the arrow keys etc. are not supported by KeyPreview....
0
intheCommented:
hi,
i had some dealing s with this problem and with help on newsgroups and teamb seemes only way was to override the components with a new one and add the DLGC_WANTTAB to the components.
for instance for any tedits i made a new tedit like below:

unit Tab_Edit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TTab_Edit = class(TEdit)
  private
    { Private declarations }
    procedure WMGetDlgCode(var message: TMessage);
      message WM_GETDLGCODE;
  protected
    { Protected declarations }
  public
    { Public declarations }
  published
    { Published declarations }
  end;

procedure Register;

implementation

procedure TTab_Edit.WMGetDlgCode(var message: TMessage);
begin
  message.Result := DLGC_WANTTAB;
end;

procedure Register;
begin
  RegisterComponents('Inthe.Future', [TTab_Edit]);
end;

end.



now in my project i drop some of these edits onto a form and do below:


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, SmackButton, Tab_Edit;

type
  TForm1 = class(TForm)
    Tab_Edit1: TTab_Edit;
    Tab_Edit2: TTab_Edit;
    Tab_Edit3: TTab_Edit;
    procedure Tab_Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Tab_Edit2KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Tab_Edit3KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Tab_Edit4KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Tab_Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (key = vk_tab) then begin
showmessage('tab pressed');
SendMessage(handle,WM_NEXTDLGCTL,0,0);
end;
end;

procedure TForm1.Tab_Edit2KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (key = vk_tab) then begin
showmessage('tab pressed');
//if you want to still use tab then send the line below else comment it out
SendMessage(handle,WM_NEXTDLGCTL,0,0);
end;
end;

procedure TForm1.Tab_Edit3KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (key = vk_tab) then begin
showmessage('tab pressed');
end;
end;

procedure TForm1.Tab_Edit4KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (key = vk_tab) then begin
showmessage('tab pressed');
end;
end;

end.






i know its a bit longwinded  :o) but it does work.
i now have a whole bunch of components that just have the wanttabs message.
hope it helps
Regards Barry

ps
happy new year to you both :-))
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

intheCommented:
ps.you can change result to this if you want arrows keys etc as well:

message.Result := DLGC_WANTARROWS or DLGC_WANTCHARS or DLGC_WANTTAB;
0
MadshiCommented:
#8-O
0
zoltan082098Author Commented:
I see that –– unfortunately ––there is no other choice. I have tried to modify the application‘s main message loop but I think it will not work.
I will create all of the the components I need adding dlgc_wanttab to them.
However I’m not stopping to wait for a better idea...
Thanks,
Zoltan  
0
intheCommented:
hehe maybe we should put all these comps on torrys :-)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zoltan082098Author Commented:
If you really want you may have these points. But I will got a lot of problems using your (Our?) idea...

So, I prefer waiting a couple of weeks, maybe somebody will have a better idea. But if you really need the points, mail me! Anyway, I don’t need them!

Thanks,
Zoltan
0
intheCommented:
? it either helped or it did'nt ..

you can reject it if you want so its still in the open questions ,i dont mind waiting a few weeks for another way but i dont think there is one...
the event just isnt built in to delphis standard components.
0
zoltan082098Author Commented:
Enjoy the points! But promise me you will announce me when you’ll find something interesting!
0
MadshiCommented:
Oh no!!!

300 points more and he has me...

#8-O
0
intheCommented:
hi zoltan sure i let you know anything that helps.

hi,
madshi im back at work tonight :-(((
that means back to not many points per day :-(

boohoo  ;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.