Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

enter key

Posted on 2004-03-20
7
Medium Priority
?
318 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 100 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

885 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