Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why do I seem to get a critical exclaim on keypress & setfocus?

Status
Not open for further replies.

CADTenchy

Technical User
Dec 12, 2007
237
0
0
GB
I have some TEdits on my app to enter data.
I'm trying to detect when enter is pressed, to move to the next edit.

This works:
Code:
procedure TSDIAppForm.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if GetKeyState(VK_Return) < 0 then  Edit2.SetFocus;
end;

but when it does I get a sound like the windows critical exclaim.

If I add a button and do this:
Code:
procedure TSDIAppForm.Button4Click(Sender: TObject);
begin
Edit2.SetFocus;
end;

I don't get the sound.

Why do I get the sound with the OnKeyPress method?


Steve (Delphi 2007 & XP)
 
don't use GetKeyState in that event.

you have two options, check for VK_RETURN in the onKeyDown event. or check for #13 in the OnKeypress event.

Cheers
/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
use this:
Code:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then 
  begin
    key := #0;
    edit2.setfocus;
  end;
end;
giovanni
 
much better, thanks guys.


Steve (Delphi 2007 & XP)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top