procedure TMainForm.KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (GetKeyState(Ord('Q'))<0) and (GetKeyState(Ord('W'))<0) and (GetKeyState(Ord('E'))<0)
then ShowMessage('You pressed it');
end;
仅当焦点设置为主窗体时,上述事件才有效。如果我运行应用程序并继续按 Tab 并将焦点更改为窗体上的任何控件,它将禁用此事件,直到我们再次将焦点更改为主窗体?
问题是 即使焦点不在主窗体中,我如何检测三个键被按下?
我还想如果我使用RegisterHotKey但在我的应用程序运行时注册Q、W 和 E并不是一个好主意。
procedure TMainForm.WMHotKey(var Msg: TWMHotKey);
begin
if ActiveCaption = 'my Form Caption' then
Begin
if Msg.HotKey = HotKey1 then
begin
//DoSomething;
end
else
if Msg.HotKey = HotKey2 then
begin
//DoSomething;
end;
End
else
//DoSomething;
end;