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.
2009-03-16 15:54:25
+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
2009-03-16 16:02:56
Indeed. But to keep F10 from activating the menu the Key parameter should also be set to 0.
mghie
2009-03-16 16:08:20
Actually, it doesn't activate the menu for me as it stands.
anon
2009-03-16 16:10:33
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
2009-03-16 16:51:34
You're right - I'll alter my answer.
anon
2009-03-16 18:01:42