Enter as Tab

Q:  How do I make it so that when the user hits <enter>, it goes to the next object as though he had hit the tab key?

A:  You need to trap the keystroke and set up your own response to it.  Try this:

procedure TMainForm.FormCreate(Sender: TObject);
begin
  keyPreview := true; {To turn the event "ON".}
end;

procedure TMainForm.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    Key := #0;
    PostMessage(Handle, WM_NEXTDLGCTL, 0, 0);{next control}
    {PostMessage(Handle, WM_NextDLGCTL, 1, 0);} {previous control}
  end;
end;

Here is some info from compu-serve (FWIW)

<<I am trying to override the default behavior of the left & right arrow keys in a dbgrid.  I am using the OnKeyDown event of DBgrid.   Overriding the right arrow as follows works fine, but trying to override the left arrow with Shift-Tab doesn't:>>

I haven't tried to mess around with the left and right arrow keys, so the following may not work.  Note that I have this implemented at the form level, with the key preview (I think that's what its called) property set to true.

Basic answer however, is that you have to us the key up procedure when you access shift, control, and alt.  Look in help under on key up.  It will explain much better than I can.  I use the following to emulate, at least in part, the same type keystrokes as in pdoxwin.  I haven't implemented the page down and page up yet. Hope this helps

procedure TFreightRateForm.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
Begin
  if (Key = VK_F9) and not((shift=[ssalt]) or (shift=[ssshift])
            or (shift=[ssctrl])) then
     case FreightTbl.State of
       dsEdit : FreightTbl.Post;
       dsInsert : FreightTbl.Post ;
    else
       FreightTbl.edit;
    end ;
    if ((Shift = [ssAlt]) and (Key = VK_BACK)) then
      FreightTbl.Cancel;
    if (Key = VK_Insert) then
      if FreightTbl.State = dsEdit then
        FreightTbl.Insert;
end;

Here is some more information on this subject:

This code also includes the processing of the <Enter> key for the entire application - including fields, etc.  The grid part is handled in the ELSE portion of the code.  The provided code does not mimic the behavior of the <Tab> key stepping down to the next record when it reaches the last  column in the grid - it moves back to the first column - .

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);

{ This is the event handler for the FORM's OnKeyPress event! }
{ You should also set the Form's KeyPreview property to True }
begin
  if Key = #13 then                              { if it's an enter key }
    if not (ActiveControl is TDBGrid) then begin { if not on a TDBGrid }
      Key := #0;                                 { eat enter key }
      Perform(WM_NEXTDLGCTL, 0, 0);              { move to next control }
    end
    else if (ActiveControl is TDBGrid) then      { if it is a TDBGrid }
      with TDBGrid(ActiveControl) do
        if selectedindex < (fieldcount -1) then  { increment the field }
          selectedindex := selectedindex +1
        else
          selectedindex := 0;
end;