Making the Enter Key act like Tab

Spread the love

This code gives the key the same habbit as the key to
change focus between Controls.

Form1.KeyPreview := True !

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    Key := #0;
    { check if SHIFT - Key is pressed }
    if GetKeyState(VK_Shift) and $8000 <> 0 then
      PostMessage(Handle, WM_NEXTDLGCTL, 1, 0)
    else
      PostMessage(Handle, WM_NEXTDLGCTL, 0, 0);
  end;
end;