I've created a Delphi VCL app with a single TMemo control, and this is the code I have.
I use it to detect Ctrl+somekey. For example, when I press Ctrl+x, it pops up the alert ctrl
and the Ctrl+x's effect (cut) was cancelled.
function IsKeyDown(Key: Integer): Boolean;
begin
Result := (GetAsyncKeyState(Key) and (1 shl 15) > 0);
end;
procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
if IsKeyDown(VK_CONTROL) then
begin
ShowMessage('ctrl');
Key := #0;
end;
end;
However, when I changed it a little bit to this:
function IsKeyDown(Key: Integer): Boolean;
begin
Result := (GetAsyncKeyState(Key) and (1 shl 15) > 0);
end;
procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
if IsKeyDown(VK_CONTROL) and IsKeyDown(VK_MENU) then
begin
ShowMessage('ctrl+alt');
Key := #0;
end;
end;
It doesn't work anymore. What I need is to detect combinations like Ctrl+Alt+f. I know I can use a TActionList, but I just want to know why my code doesn't work.