Solved

enter key

Posted on 2004-03-20
7
311 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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