Solved

How to catch tab key press

Posted on 1997-04-23
4
226 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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