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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

detecting F1 press not working?

Status
Not open for further replies.

CADTenchy

Technical User
Dec 12, 2007
237
GB
I'm trying to detect when a F key, like F1 is pressed on my form.

I've set the form's KeyPreview property to True.

I've tried a few variations from tips I've found, but none work.
This works if I change the #112 to 65 and press A:
Code:
procedure TMainForm.FormKeyPress(Sender: TObject; var Key: Char);
begin
if key in [#112] then Label7.Caption := 'F1 pressed';
key := #0;
end;

But #112 (ASCII for F1??) does not, and any mention of VK_F1 gives an error basically saying non integer.

How do I get this to work?

Steve (Delphi 2007 & XP)
 
use the onkeydown method instead of onkeypress, there you can check against VK_F1.

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Use FormKeyDown instead. FormKeyPress only works for alphanumerics and not function keys.
 
lol glenn, a minute too late :)

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Actually seconds - I saw your post as mine went through. It didn't take that long for me to type it either.
 
Thanks both, that worked fine. Great minds think alike huh, at same time :)


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

Part and Inventory Search

Sponsor

Back
Top