-13 Votes

Delphi: Function keys like F1, F2 and F3 do not work in FormKeyDown event

Question by Guest | 2012-08-10 at 11:55

In the FormKeyDown event, I want to react to the function keys (F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11 and F12) and assign an appropriate action (HotKey). For this I use the following code:

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
  if Key = VK_F1 then Function1();
  if Key = VK_F2 then Function2();
  if Key = VK_F3 then Function3();

Problem: For some reason, it does not work. Apparently, when pressing F1, not even the FormKeyDown event of the form is called! What am I doing wrong? I have checked the code for many times and with all other Virtual Keys such as VK_Space, it works perfectly! Only with the function keys there is a problem!

4Best Answer6 Votes

Your code can remain exactly as it is, just try to start the program outside of the IDE. When you are running the program in Delphi, the function keys are assigned by Delphi and therefore you can not access their key event via the OnKeyyDown.

But if you start the program outside of Delphi, it should work.
2012-08-12 at 17:47

ReplyPositive Negative
33 Votes

I had the same problem! And that is the solution! Thank you very very much! Without your tipp, I could never get it!
2012-09-24 at 18:09

Positive Negative

Related Topics

Delphi: System-Wide HotKey

Tutorial | 1 Comment

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.


Ask your own question or write your own article on askingbox.com. That’s how it’s done.