Reputation: 2265
I'm using the KeyPress event on a text entry field in Lazarus on Windows7 to detect and interpret certain key sequences but I want to detect F1 to pop up a Help dialog.
I can capture #13 as the Return key no problem, but using #112 does not seem to catch F1.
My code is as follows:
procedure TForm1.keyCatcherKeyPress(Sender: TObject; var Key: char);
begin
if ( AnsiContainsStr('0123456789',Key) ) then
begin
{my processing code}
end
else
if ( Key = #13 ) then
begin
{my processing code}
... some other key checks that all work fine...
else
if ( Key = #112) then
showHelp();
Is F1 catchable this way and is this the right code to look for?
Upvotes: 1
Views: 1312
Reputation: 2265
Thanks To TLama's guidance above I found the following post on the Lazarus forum which got me a solution:
http://forum.lazarus.freepascal.org/index.php?topic=14814.0
My code for key press detection is now split between normal characters being detected with the KeyPress
event and 'special' keypresses being detected with the OnKeyDown
event.
procedure TForm1.keyCatcherKeyPress(Sender: TObject; var Key: char);
begin
if ( AnsiContainsStr('0123456789',Key) ) then
begin
{my processing code}
end
else
... some other key checks that all work fine...;
and
if ( Key = VK_Return ) then
begin
{my processing code}
else
if ( Key = VK_F1 ) then
showHelp();
Upvotes: 1