Board index » delphi » How simulate a TAB

How simulate a TAB

How can i simulate a TAB with another key, for example RETURN, to make
possible use an input from a component TEdit (or another that can have
focus) to another in the form ?

Thanks, Rob

 

Re:How simulate a TAB


How can i simulate a TAB with another key, for example RETURN, to make
possible use an input from a component TEdit (or another that can have
focus) to another in the form ?

Thanks, Rob

Re:How simulate a TAB


How can i simulate a TAB with another key, for example RETURN, to make
possible use an input from a component TEdit (or another that can have
focus) to another in the form ?

Thanks, Rob

Re:How simulate a TAB


On Thu, 13 Jan 2000 16:51:04 +0100, "Roberto Albano"

Quote
<albanorobe...@hotmail.com> wrote:
>How can i simulate a TAB with another key, for example RETURN, to make
>possible use an input from a component TEdit (or another that can have
>focus) to another in the form ?

Using Tab to navigate between child controls in a window is a Windows
convention. However, it is possible to override this default behavior. You
can do this in Delphi once, at the TForm level, obviating the need to write
a handler for each control.

First, you have to force all keystrokes to be reviewed by the containing
TForm prior to them being passed on to the individual child controls. This
is done by setting the KeyPreview property of the TForm to True.

The last step involves evaluating the keystrokes seen by the TForm and
reacting to only the Enter key (#13 or the Windows constant VK_RETURN). If
the Enter key is encountered, call the Perform method to move to the next
child control with a call to the form's Perform method and then nullify the
keystroke. This is done in an OnKeyPress event procedure for the TForm:

  procedure Form1.FormKeyPress(Sender: TObject; var Key: Char);
  begin
    if (Ord(Key) = VK_RETURN { the Enter key }) then begin
      { Always nullify keystrokes handled }
      Key := #0;
      { Signal to move focus to next control }
      Perform(WM_NEXTDLGCTL, 0, 0);
    end;
  end;

A value of zero for the second parameter of Perform (the WParam parameter)
moves focus to the next control in the tab-order. A value of negative one
moves focus to the prior control in the tab-order. So you could trap for
two keys and either move forward or back in one routine depending on the
key pressed. Below, Enter moves to the next control and UpArrow to the
prior control.

  procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
    Shift: TShiftState);
  begin
    if (Key in [VK_RETURN, VK_UP]) then begin
      if (Key = VK_RETURN { the Enter key }) then
        { Signal to move focus to next control }
        Perform(WM_NEXTDLGCTL, 0, 0)
      else { the UpArrow key }
        { Signal to move focus to prior control }
        Perform(WM_NEXTDLGCTL, -1, 0);
      { Always nullify keystrokes handled }
      Key := 0;
    end;
  end;

Note that because the UpArrow key does not trigger an OnKeyPress event, the
OnKeyUp event must be used instead. In hanlders for OnKeyUp, the Key
parameter is of type Word, not Char as in OnKeyPress. Handle the difference
in data types as indicated.

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Steve Koterski              "Health nuts are going to feel stupid someday,
Felton, CA                  lying in hospitals dying of nothing."
                                                              -- Redd Foxx

Re:How simulate a TAB


Steve's way is a bit more conventional than mine but I like the fact
that the form does not have to filter each keystroke to complete this
method of converting ENTER to TAB (note that this method lets you
convert ANY keystroke to ANY OTHER keystroke... great fun at parties
:)

In your form's PRIVATE section add:

     Procedure CMDialogKey(Var Msg:TWMKey); message CM_DIALOGKEY;

in your form's IMPLEMENTATION section add:

   Procedure TfrmMainMenu.CMDialogKey(Var Msg: TWMKey);
   Begin
      If NOT (ActiveControl Is TButton) Then
         If Msg.Charcode = 13 Then
            Msg.Charcode := 9;
      inherited;
   End;

For the less savvy, CharCode 9 is TAB and CharCode 13 is ENTER. These
are ASCII scan codes.

On Thu, 13 Jan 2000 22:59:26 GMT, koter...@NOSPAMgte.net (Steve

Quote
Koterski) wrote:
>On Thu, 13 Jan 2000 16:51:04 +0100, "Roberto Albano"
><albanorobe...@hotmail.com> wrote:

>>How can i simulate a TAB with another key, for example RETURN, to make
>>possible use an input from a component TEdit (or another that can have
>>focus) to another in the form ?

>Using Tab to navigate between child controls in a window is a Windows
>convention. However, it is possible to override this default behavior. You
>can do this in Delphi once, at the TForm level, obviating the need to write
>a handler for each control.

>First, you have to force all keystrokes to be reviewed by the containing
>TForm prior to them being passed on to the individual child controls. This
>is done by setting the KeyPreview property of the TForm to True.

>The last step involves evaluating the keystrokes seen by the TForm and
>reacting to only the Enter key (#13 or the Windows constant VK_RETURN). If
>the Enter key is encountered, call the Perform method to move to the next
>child control with a call to the form's Perform method and then nullify the
>keystroke. This is done in an OnKeyPress event procedure for the TForm:

>  procedure Form1.FormKeyPress(Sender: TObject; var Key: Char);
>  begin
>    if (Ord(Key) = VK_RETURN { the Enter key }) then begin
>      { Always nullify keystrokes handled }
>      Key := #0;
>      { Signal to move focus to next control }
>      Perform(WM_NEXTDLGCTL, 0, 0);
>    end;
>  end;

>A value of zero for the second parameter of Perform (the WParam parameter)
>moves focus to the next control in the tab-order. A value of negative one
>moves focus to the prior control in the tab-order. So you could trap for
>two keys and either move forward or back in one routine depending on the
>key pressed. Below, Enter moves to the next control and UpArrow to the
>prior control.

>  procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
>    Shift: TShiftState);
>  begin
>    if (Key in [VK_RETURN, VK_UP]) then begin
>      if (Key = VK_RETURN { the Enter key }) then
>        { Signal to move focus to next control }
>        Perform(WM_NEXTDLGCTL, 0, 0)
>      else { the UpArrow key }
>        { Signal to move focus to prior control }
>        Perform(WM_NEXTDLGCTL, -1, 0);
>      { Always nullify keystrokes handled }
>      Key := 0;
>    end;
>  end;

>Note that because the UpArrow key does not trigger an OnKeyPress event, the
>OnKeyUp event must be used instead. In hanlders for OnKeyUp, the Key
>parameter is of type Word, not Char as in OnKeyPress. Handle the difference
>in data types as indicated.

>_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
>Steve Koterski              "Health nuts are going to feel stupid someday,
>Felton, CA                  lying in hospitals dying of nothing."
>                                                              -- Redd Foxx

-----
Bill Artemik
Software Engineer
Droste Consultants, Inc.
b...@droste1.com

-------------------------

Attn: Spammers -> don't send to the following addresses:
first.l...@whitehouse.gov consumerl...@ftc.gov c...@ftc.gov fr...@uspis.gov u...@ftc.gov rh...@fcc.gov jque...@fcc.gov sn...@fcc.gov rch...@fcc.gov custo...@usps.gov
postmas...@agis.net ab...@agis.net r...@agis.net dns-ad...@agis.net n...@agis.net
hostmas...@agis.net p...@agis.net webmas...@agis.net docum...@agis.net ip-requ...@agis.net rout...@agis.net n...@agis.net  account...@agis.net i...@agis.net a...@agis.net h...@agis.net
emai...@qlink2info.com  sim...@answerme.com hostmas...@inreach.com a...@inreach.com
postmas...@emaildirect.net  ab...@emaildirect.net r...@emaildirect.net
postmas...@e-bizness.com ab...@e-bizness.com  r...@e-bizness.com com...@iaw.on.ca
maxem...@united-cbe.org dom...@emaildirect.net dom...@hosting.netcom.com
sa...@marketingmasters.com  biz...@softcom.net getpa...@technosurf.com
dom...@hosting.netcom.com a...@additionalbenefits.com ls...@ne.infi.net
ltcli...@ne.infi.net ltper...@ne.infi.net ab...@alladvantage.com ab...@hotmail.com

Other Threads