Board index » delphi » Simulate tab Key when Enter Key Pressed

Simulate tab Key when Enter Key Pressed

I need to go against all rules and have the customer be able to hit the
enter key from an edit control or combo box and have it do the same thing as
a tab.  I know all the reasons not to do this but this is for point of sale
software and the customer insists that the enter key move the focus from
control to control.
Thanks! For your help.
Mike Bancroft
 

Re:Simulate tab Key when Enter Key Pressed


Quote
Michael Bancroft wrote:
> I need to go against all rules and have the customer be able to hit the
> enter key from an edit control or combo box and have it do the same thing as
> a tab.  I know all the reasons not to do this but this is for point of sale
> software and the customer insists that the enter key move the focus from
> control to control.
> Thanks! For your help.
> Mike Bancroft

This seems to work.

  private
    { Private declarations }
    procedure OnMessage(var Msg: tagMSG; var Handled: Boolean);
  public
    { Public declarations }
  end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnMessage := OnMessage;
end;

procedure TForm1.OnMessage(var Msg: tagMSG; var Handled: Boolean);
begin
  if Msg.message = WM_KEYDOWN then
  begin
    if Msg.wParam = VK_RETURN then
      keybd_event(VK_TAB, 0, 0, 0);
  end;
end;

Re:Simulate tab Key when Enter Key Pressed


"Michael Bancroft"

Quote
> I need to go against all rules and have the customer be
> able to hit the enter key from an edit control or combobox
> and have it do the same thing as a tab.  I know all the
> reasons not to do this but this is for point of sale
> software and the customer insists that the enter key move
> the focus from control to control.
> Thanks! For your help.
> Mike Bancroft

One option would be to use SelectNext();

In a OnKeyPress event or something like that

if Key = #13 then
begin
   SelectNext( ActiveControl, True, True);
   Key := #0; // avoid annoying beep.
end;

--
Pieter

Re:Simulate tab Key when Enter Key Pressed


I guess the following would be the most direct way of doing the trick,

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = Char(VK_RETURN) then begin
    Key := #0;
    PostMessage(Handle, WM_NEXTDLGCTL, 0, 0);
  end;
end;

Regs,
Niels Ebbesen

Quote
"Michael Bancroft" <mi...@southerntime.com> wrote in message

news:3c3a0569_2@dnews...
Quote
> I need to go against all rules and have the customer be able to hit the
> enter key from an edit control or combo box and have it do the same thing
as
> a tab.  I know all the reasons not to do this but this is for point of
sale
> software and the customer insists that the enter key move the focus from
> control to control.
> Thanks! For your help.
> Mike Bancroft

Re:Simulate tab Key when Enter Key Pressed


I guess the following would be the most direct way of doing the trick,

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = Char(VK_RETURN) then begin
    Key := #0;
    PostMessage(Handle, WM_NEXTDLGCTL, 0, 0);
  end;
end;

Regs,
Niels Ebbesen

Quote
"Michael Bancroft" <mi...@southerntime.com> wrote in message

news:3c3a0569_2@dnews...
Quote
> I need to go against all rules and have the customer be able to hit the
> enter key from an edit control or combo box and have it do the same thing
as
> a tab.  I know all the reasons not to do this but this is for point of
sale
> software and the customer insists that the enter key move the focus from
> control to control.
> Thanks! For your help.
> Mike Bancroft

Other Threads