Skip to content

Instantly share code, notes, and snippets.

@martinusso
Created November 21, 2011 10:33
Show Gist options
  • Save martinusso/1382264 to your computer and use it in GitHub Desktop.
Save martinusso/1382264 to your computer and use it in GitHub Desktop.
Make the Enter key work like Tab in Delphi applications
{
In the Main Form of application
}
procedure TMainUI.DoEnterAsTab(var Msg: TMsg; var Handled: Boolean);
begin
if Msg.Message = WM_KEYDOWN then
begin
if (not (Screen.ActiveControl is TCustomMemo)) and (not (Screen.ActiveControl is TButtonControl)) then
begin
if Msg.wParam = VK_RETURN then
Screen.ActiveForm.Perform(WM_NextDlgCtl, 0, 0);
end;
end;
end;
procedure TMainUI.FormCreate(Sender: TObject);
begin
// At the end of the method, add:
Application.OnMessage := DoEnterAsTab;
end;
@martinusso
Copy link
Author

martinusso commented Nov 21, 2011

Line 12 was changed from:

Keybd_event(VK_TAB, 0, 0, 0);

to:

Screen.ActiveForm.Perform(WM_NextDlgCtl, 0, 0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment