Solved

How to catch tab key press

Posted on 1997-04-23
4
221 Views
Last Modified: 2010-04-04
I'd like to know when the user presses the tab key in my form.  It would a nice bonus to know which control the user was in when the tab key was pressed
0
Comment
Question by:bperry
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
sperling earned 200 total points
ID: 1335687
Declare this procedure in your forms "private" section:

procedure AppMessage (var msg : TMessage; var Handled : BOOLEAN);

procedure TForm1.AppMessage (var msg : TMsg; var Handled : BOOLEAN);
begin
  if (msg.message=WM_KEYDOWN) and (msg.wParam=VK_TAB) then begin
    // TAB was pressed in some form.
    if Screen.Forms[0] = Self then begin
      // TAB was pressed in this form
      if ActiveControl<>nil then begin
        // ActiveControl.Name = Name of control that has focus
      end;
    end;
  end;
end;


in the form OnCreate event:
  Application.OnMessage := AppMessage;


Regards,

Erik.
0
 

Author Comment

by:bperry
ID: 1335688
The line above should be

 procedure AppMessage (var msg : TMsg;  ...

not

procedure AppMessage (var msg : TMessage

But otherwise it's perfect.
0
 

Author Comment

by:bperry
ID: 1335689
The line above should be

procedure AppMessage (var msg : TMsg;  ...

not

procedure AppMessage (var msg : TMessage

But otherwise it's perfect.
0
 
LVL 3

Expert Comment

by:sperling
ID: 1335690
Oops...

That's what happens when I modify the code after pasting it into Netscape ;)

Erik.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now