Delphi 7 - How can I make the <enter> key on a button ?

Basically the button needs to act like enter key on this particular Memo, is that possible?
John86aAsked:
Who is Participating?
 
Ephraim WangoyaCommented:

If you want to use messages instead, do it like this
procedure TForm3.Button1Click(Sender: TObject);
begin
  PostMessage(Memo1.Handle, WM_KEYDOWN, Ord(#13), 0);
  Memo1.SetFocus;
end;

Open in new window

0
 
Ephraim WangoyaCommented:
this way
procedure TForm3.Button1Click(Sender: TObject);
begin
  Memo1.SetFocus;
  Keybd_Event(VK_RETURN,   1, 0, 0);
end;

Open in new window

0
 
Ephraim WangoyaCommented:

Modify this to
procedure TForm3.Button1Click(Sender: TObject);
begin
  Memo1.SetFocus;
  Keybd_Event(VK_RETURN, 1, 0, 0);
  Keybd_Event(VK_RETURN, 1, KEYEVENTF_KEYUP, 0);
end;

Open in new window

0
 
John86aAuthor Commented:
That helped me track where my application was replacing <Enter> for <Tab> thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.