Board index » cppbuilder » How to use Enter key to move (tab) from one component to the next

How to use Enter key to move (tab) from one component to the next

I want the user to be able to move from one component to the next by
using the Enter key.  I want the Enter key to behave like the Tab key
when it comes to this.  I can catch the Enter key in the OnKeyPress
with the VK_RETURN, but what do I replace the Key with to make it
think that Tab was pressed.

Or is there another way of doing it.

All responses will be greatly appreciated.

Thanks.

 

Re:How to use Enter key to move (tab) from one component to the next


Once you have swallowed the key (set it to 0), you can do a couple of
things.  Use the API to send a message; NextDlgItem I believe is the
function.  Or you could use the VCL to set the focus for the next control.

HTH,  Brent

Quote
tt <t...@insightmed.com> wrote in message news:3a5b9b28$1_2@dnews...
> I want the user to be able to move from one component to the next by
> using the Enter key.  I want the Enter key to behave like the Tab key
> when it comes to this.  I can catch the Enter key in the OnKeyPress
> with the VK_RETURN, but what do I replace the Key with to make it
> think that Tab was pressed.

> Or is there another way of doing it.

> All responses will be greatly appreciated.

> Thanks.

Re:How to use Enter key to move (tab) from one component to the next


Quote
"tt" <t...@insightmed.com> wrote in message news:3a5b9b28$1_2@dnews...
> I want the user to be able to move from one component to the next by
> using the Enter key.  I want the Enter key to behave like the Tab key
> when it comes to this.  I can catch the Enter key in the OnKeyPress
> with the VK_RETURN, but what do I replace the Key with to make it
> think that Tab was pressed.

> Or is there another way of doing it.

> All responses will be greatly appreciated.

> Thanks.

Hi tt,
try to do this in the OnKeyPress function:

  if (Key == VK_RETURN)
    {
      keybd_event(VK_TAB, 0, 0, 0);
      keybd_event(VK_TAB, 0, KEYEVENTF_KEYUP, 0);
    }

Re:How to use Enter key to move (tab) from one component to the next


Quote
tt <t...@insightmed.com> wrote in message news:3a5b9b28$1_2@dnews...
> I want the user to be able to move from one component to the next by
> using the Enter key.  I want the Enter key to behave like the Tab key
> when it comes to this.

Set all of your edit key press events to the same handler of....

void __fastcall TForm1::EditKeyPress(TObject *Sender, char &Key)
{
 if (Key == VK_RETURN)
   {
    Key = 0;
      PostMessage(Handle,WM_NEXTDLGCTL,0,0);
   }

Quote
}

You must also make sure that none of your buttons have their default
property set to true, otherwise they act as though they've been clicked. Bit
buttons can set this property to true automatically so keep an eye out.
(e.g. if kind is set to bkOK)

HTH Sid

Quote

Re:How to use Enter key to move (tab) from one component to the next


Thanks everyone for all your responses.

Re:How to use Enter key to move (tab) from one component to the next


Quote
>       PostMessage(Handle,WM_NEXTDLGCTL,0,0);

Also see TWinControl's FindNextControl method.

+=====================================================+
| Jonathan Arnold (mailto:jdarn...@buddydog.org)      |
|         Comprehensive C++Builder link site:         |
| http://www.buddydog.org/C++Builder/c++builder.html  |
+=====================================================+

Other Threads