gpt4 book ai didi

德尔福XE2 : How to prevent the Alt key stealing focus?

转载 作者:行者123 更新时间:2023-12-03 15:50:24 27 4
gpt4 key购买 nike

当光标位于例如在编辑字段中,按下并释放 Alt 键(不按任何其他键)会导致编辑字段失去焦点。对于任何其他集中控制也会发生这种情况。对于任何集中控制,如何在 Delphi 程序中防止这种情况发生?

最佳答案

要减少意外后果,更好的方法是极其精确 - 我建议:

在您的表单中,覆盖 WndProc :

TForm1 = class(TForm)
Edit1: TEdit;
private
FSuppress : boolean;
protected
procedure WndProc(var Message : TMessage); override;
end;

并像这样实现:

procedure TForm1.WndProc(var Message : TMessage);
begin
if (Message.Msg = WM_SYSCOMMAND) and
(Message.WParam = SC_KEYMENU) and
FSuppress then Exit;

inherited WndProc(Message);
end;

这是系统命令的 Windows 消息,以及指示它用于检索由击键触发的菜单的特定 WParam。在您希望保持焦点的任何控件上设置 FSuppress :

procedure TForm1.Edit1Enter(Sender: TObject);
begin
FSuppress := true;
end;

procedure TForm1.Edit1Exit(Sender: TObject);
begin
FSuppress := false;
end;

这不会禁用 ALT 键,但会在 Edit1 获得焦点时禁用菜单的激活。重要的是,诸如 ALT + F4 退出程序或 ALT+TAB 切换窗口之类的快捷键仍然有效。

但是,我同意大多数评论,因为这可能不是针对您的用户群的 LCD 的最佳解决方案。你实际上是在削弱有能力的用户的程序,以迎合无能的用户的失败。或许可以将其作为 Windows 粘滞键或针对不同残疾人士的辅助选项的选项。

关于德尔福XE2 : How to prevent the Alt key stealing focus?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16828250/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com