Solved

enter key

Posted on 2004-03-20
7
307 Views
Last Modified: 2010-04-05
how do you simulate enter key pressed?
Example: If you have a  button..So when you hit enter
it behaves like you clicked on a button
0
Comment
Question by:Bosanac
7 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10642321
Not sure what you really want, but you can test for a Enter key in your forms onKeyDown event

 procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if key = VK_RETURN then beep();
end;

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10642325
Explain more what you are trying to do~

Shane
0
 

Author Comment

by:Bosanac
ID: 10642840
To have enter click the button...
if key enter then button1.clickself on keydown...
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 17

Expert Comment

by:mokule
ID: 10643382
Button1.Default := True
All other buttons on a form should have Default := False
0
 

Expert Comment

by:Vatnam
ID: 10643505
Set the focus on the button you want like :

Button1.SetFocus

When you now press the enter key you'll get the normal button's 'on click' event.
0
 
LVL 17

Expert Comment

by:mokule
ID: 10643576
If You've got four edits and two buttons on a form.
You can do like this. If I understand what You mean.

procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit3.Text := Edit1.Text;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Edit4.Text := Edit2.Text;
end;

procedure TForm1.Edit1Enter(Sender: TObject);
begin
  Button1.Default := True;
end;

procedure TForm1.Edit2Enter(Sender: TObject);
begin
  Button2.Default := True;
end;

procedure TForm1.Edit1Exit(Sender: TObject);
begin
  Button1.Default := False;
end;

procedure TForm1.Edit2Exit(Sender: TObject);
begin
  Button2.Default := False;
end;

Marek
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 25 total points
ID: 10643623
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if key = VK_RETURN then Button1.click;
end;

OR

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
 if (Ord(Key) = VK_RETURN ) then Button1.Click
end;

Set forms KeyPreview = true

Shane
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now