Solved

How to catch tab key press

Posted on 1997-04-23
4
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

726 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