RAD Studio 10.4.1 is now available! Learn more. Looking for discounts? Visit our Special Offers page!
Delphi

Detecting tab key press

Author: Embarcadero USA

 Question and Answer Database

FAQ2060D.txt   Detecting tab key press
Category   :VCL
Platform    :All
Product    :All 32 bit  

Question:
Since the KeyPress and the KeyDown events do not get called 
for the tab key, how do I trap the tab key at the form level?



Answer:
At form level, the tab key is generally handled by Windows. The
following example demonstrates creating a CM_Dialog message 
handler to trap for Dialog keys. The code surfaces the tab 
character through the KeyPress event.

Example:

type
  TForm1 = class(TForm)
  private
    procedure CMDialogKey( Var msg: TCMDialogKey );
     message CM_DIALOGKEY;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.CMDialogKey(var msg: TCMDialogKey);
begin
  if msg.Charcode <> VK_TAB then
   inherited;
end;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_TAB then
    Form1.Caption := 'Tab Key Down!';
end;


7/16/98 4:31:28 PM
 

Article originally contributed by


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Learn More About Upgrading

Related posts
C++News

Using C++17 Algorithms Library Parallel Sorting with C++Builder 10.4 Sydney for Win32 and Win64

C++

What's New in the GetIt Package Manager - June 2020

C++

RAD Studio 10.4 Now Available, Learn More

C++NewsRAD Studio

Open for Business with 10.4! - May 2020 GM Update

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES