delphi – 当另一个控件具有焦点时,我的表单如何检测KeyDown事件
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; 只有将焦点设置为主窗体时,上述事件才有效. 问题是 我也想过如果我使用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; 解决方法
您可以将表单的
KeyPreview 设置为true.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |