tags:

views:

312

answers:

2

I'm trying to capture the F10 key in Delphi, but it seems to keep going to activating the menu because it gets converted from the vk_F10 to vk_menu or something.

+1  A: 

Hello Stephen,

If you're on Windows, here's some code to make a keyboard hook using the Windows API: http://www.delphitricks.com/source-code/windows/install_a_keyboard_hook.html

Wadih M.
+5  A: 

The following OnKeyDown event added to my main form should work. Note you ned to set the key parameter to zero to prevent menu activation:

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
   if key = VK_F10 then begin
     Label1.Caption := 'You hit F10';
     key := 0;
   end;
end;
anon
Indeed. But to keep F10 from activating the menu the Key parameter should also be set to 0.
mghie
Actually, it doesn't activate the menu for me as it stands.
anon
it probably does activate the menu, but that will be lost by the showmessage changing focus. Try setting a label caption instead, and see if it does it then (with a menu present of course!)
mj2008
You're right - I'll alter my answer.
anon