Board index » delphi » OnKeyDown event and <TAB>

OnKeyDown event and <TAB>

Hi,

I want to check whether the <TAB> key was pressed while focus is on a TMaskEdit
component. However, the program does not enter the OnKeyDown event-handler when
the <TAB> key is pressed. It works for most other keys.

Is there a way to check whether the TAB key was pressed (I still want the program
to shift focus as usual)?

Nils

 

Re:OnKeyDown event and <TAB>


Quote
Nils C. Hertzberg wrote:
> I want to check whether the <TAB> key was pressed while focus is on a TMaskEdit
> component. However, the program does not enter the OnKeyDown event-handler when
> the <TAB> key is pressed. It works for most other keys.

You only can receive TAB keys when you override the component,
catch the WM_GETDLGCODE message and return
   msg.result := msg.result or DLGC_WANTTAB;

Quote
> Is there a way to check whether the TAB key was pressed (I still want the program
> to shift focus as usual)?

To make the program act as usual you have to call a
   SendMessage(GetParentForm(self).Handle, CM_DIALOGKEY, key, 0);
right after you handled the message in your KeyDown method.

Hope this helps
   Guido
--
Guido Schoepp
eMail: 101644.2...@compuserve.com  Bonner GeneralAnzeiger
Voice: +49 (228) 6688-187          Justus-von-Liebig-Strasse
  Fax: +49 (228) 6688-170          D-53121 Bonn

Re:OnKeyDown event and <TAB>


Quote
Guido Schoepp wrote:

> Nils C. Hertzberg wrote:
> > I want to check whether the <TAB> key was pressed while focus is on a TMaskEdit
> > component. However, the program does not enter the OnKeyDown event-handler when
> > the <TAB> key is pressed. It works for most other keys.

> You only can receive TAB keys when you override the component,
> catch the WM_GETDLGCODE message and return
>    msg.result := msg.result or DLGC_WANTTAB;

> > Is there a way to check whether the TAB key was pressed (I still want the program
> > to shift focus as usual)?

> To make the program act as usual you have to call a
>    SendMessage(GetParentForm(self).Handle, CM_DIALOGKEY, key, 0);
> right after you handled the message in your KeyDown method.

> Hope this helps
>    Guido

This is what I was looking for, thanks. However, I solved the problem by using the
OnKeyUp event handler, which works fine. The program shifts focus to the next control
before the OnKeyUp event is activated, but I solve that by keeping track of the
previous active control.

Nils

Other Threads