【问题标题】:IDE Plugin to disable the Insert keyIDE 插件禁用插入键
【发布时间】:2020-05-12 22:27:47
【问题描述】:

我一直在使用 Delphi (10.3 Rio) 的 IDE 插件来禁用插入键(有人真的使用过输入模式吗?)。

它可以很好地安装到 IDE 中,但是如果我卸载它,当我按下插入键时会发生异常。

谁能帮帮我?

这里是更新的来源: (我添加了finalization部分,还是报错)

unit MyBinding;

interface

procedure Register;

implementation

uses Windows, Classes, SysUtils, ToolsAPI, Vcl.Menus;

type
  TLearnDelphiKeyBinding = class(TNotifierObject, IOTAKeyboardBinding)
  private
    procedure DoNothing(const Context: IOTAKeyContext; KeyCode: TShortCut; var BindingResult: TKeyBindingResult);

  public
    function GetBindingType: TBindingType;
    function GetDisplayName: string;
    function GetName: string;
    procedure BindKeyboard(const BindingServices: IOTAKeyBindingServices);
  end;

var
  LearnDelphiKeyBindingIndex : integer = 0;

procedure Register;
begin
  LearnDelphiKeyBindingIndex := (BorlandIDEServices as IOTAKeyBoardServices).AddKeyboardBinding(TLearnDelphiKeyBinding.Create);
end;

procedure TLearnDelphiKeyBinding.BindKeyboard(const BindingServices: IOTAKeyBindingServices);
begin
  BindingServices.AddKeyBinding([ShortCut(VK_INSERT, [])], DoNothing, nil);
end;

function TLearnDelphiKeyBinding.GetBindingType: TBindingType;
begin
  Result := btPartial;
end;

function TLearnDelphiKeyBinding.GetDisplayName: string;
begin
  Result := 'Disable Insert';
end;

function TLearnDelphiKeyBinding.GetName: string;
begin
  Result := 'LearnDelphi.DisableInsert';
end;

procedure TLearnDelphiKeyBinding.DoNothing(const Context: IOTAKeyContext;
  KeyCode: TShortCut; var BindingResult: TKeyBindingResult);
begin
  BindingResult := krHandled;
end;

initialization
finalization
  if LearnDelphiKeyBindingIndex > 0 then
    (BorlandIDEServices as IOTAKeyboardServices).RemoveKeyboardBinding(LearnDelphiKeyBindingIndex);

end.

【问题讨论】:

  • "有人真的使用过打字模式吗?"我每天使用它很多次。这是一个实际的例子(有点下,在它自己的部分下):rejbrand.se/rejbrand/article.asp?ItemIndex=479
  • @AndreasRejbrand 不完全是一个引人注目的例子,但我会记住它——也许有一天我会记得使用它——假设我没有禁用 Insert 键。

标签: delphi plugins


【解决方案1】:

您需要在finalization 期间调用IOTAKeyboardServices.RemoveKeyboardBinding(),将IOTAKeyboardServices.AddKeyboardBinding() 返回的值传递给它(您当前没有保存)。

查看 David Hoyle 博客中的 Chapter 4: Key Bindings and Debugging Tools,它提供了使用 OpenTools API 的键盘绑定向导示例。

【讨论】:

  • 我在禁用包后按插入时仍然遇到访问冲突,不确定这里出了什么问题。我已经更新了问题中的源代码
猜你喜欢
  • 2011-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多