修改 转换具有100多种表单的程序时。其中一些弹出菜单以 Insert 键为快捷键。在Mac键盘甚至Mac OS上都不会出现此键。
因此我们需要在部署mac时更改所有这些快捷方式。
解决方案
码
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;