Solved

enter key

Posted on 2004-03-20
7
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month9 days, 2 hours left to enroll

617 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