更改MacOS上的快捷方式,以便插入'键

时间:2015-09-28 11:55:49

标签: delphi firemonkey

修改 转换具有100多种表单的程序时。其中一些弹出菜单以 Insert 键为快捷键。在Mac键盘甚至Mac OS上都不会出现此键。

因此我们需要在部署mac时更改所有这些快捷方式。

解决方案

  1. David Hefferman建议:在Streaming a Form时,循环浏览所有操作和快捷方式,然后更改快捷方式。
  2. 更改新快捷键的键处理以映射到旧快捷键(在表单中)。并在弹出菜单显示时更改快捷方式,以显示新的快捷方式。
  3. TMenuItem = class(FMX.Menus.TMenuItem)
      protected
        procedure ApplyStyle; override;
        procedure DialogKey(var Key: Word; Shift: TShiftState); override;
      end;
    
    TForm = class(FMX.Forms.TForm)
      public
        procedure KeyDown(var Key: Word; var KeyChar: System.WideChar; Shift: TShiftState); override;
      end;
    
     procedure TMenuItem.ApplyStyle;
    begin
      inherited;
      //When the popupmenu is shown, make shure that the shortcut is showing the new one
      if self.ShortCut=45 then
        self.ShortCut := 16462; //new shortcut (Ctrl+N)
    end;
    
    procedure TMenuItem.DialogKey(var Key: Word; Shift: TShiftState);
    begin
      if (key = 45) AND (ShortCut = 16462)  then begin //form has passed old shortcut so change it back
        ShortCut:= 45;
        inherited;
        ShortCut := 16462; //revert to new
      end else begin
        inherited;
      end;
      if self.ShortCut=45 then //if the shortcut was still mapped to old shortcut, map to new
        self.ShortCut := 16462;
    end;
    
    procedure TForm.KeyDown(var Key: Word; var KeyChar: System.WideChar; Shift: TShiftState);
    begin
      //new Shortcut is ctrl+N        
      if (key=vkN) AND (ssCtrl in Shift) then begin
        key := 45; //change to the code for insert
        Shift := shift - [ssCTRL]; //remove Ctrl
      end;
      inherited;
    end;
    

0 个答案:

没有答案