Solved

How to catch tab key press

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
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…

706 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

20 Experts available now in Live!

Get 1:1 Help Now