【发布时间】:2021-08-29 06:21:59
【问题描述】:
在 Windows 10 x64 中的 Delphi 10.4.2 Win32 VCL 应用程序中,我使用此代码以编程方式为弹出菜单项上的 DELETE 键创建快捷方式字符串:
mGalleryDeleteSelected.Caption := mGalleryDeleteSelected.Caption + #9 + MyShortcutToString(VK_DELETE, []) + ' ';
这是源代码:
function MyGetKeyName(AKey: Integer): string;
var
name: array[0..128] of Char;
begin
FillChar(name, SizeOf(name), 0);
GetKeyNameText(MapVirtualKey(AKey, 0) shl 16, @name[0], Length(name));
Result := name;
end;
function MyModifierVirtualKey(AModifier: Integer): Integer;
begin
case AModifier of
Ord(ssShift):
Result := VK_SHIFT;
Ord(ssCtrl):
Result := VK_CONTROL;
Ord(ssAlt):
Result := VK_MENU;
else
Result := 0;
end;
end;
function MyShortcutToString(AKey: Integer; AShiftState: TShiftState = []): string;
begin
Result := '';
for var Modifier in AShiftState do
begin
var ModifierKey := MyModifierVirtualKey(Ord(Modifier));
if ModifierKey <> 0 then
Result := Result + IfThen(not Result.IsEmpty, '+') + MyGetKeyName(ModifierKey);
end;
Result := Result + IfThen(not Result.IsEmpty, '+') + MyGetKeyName(AKey);
end;
但是,我没有获得普通 DELETE 键的快捷方式字符串,而是获得了数字键盘上(辅助?)逗号/删除键的快捷方式字符串:
因为我有一个德语 Windows,这里是翻译:
KOMMA = 逗号
ZEHNERTASTATUR = 数字小键盘
德语键盘上的默认 Delete 键带有标签“entf”(“Entfernen”的缩写)
如果数字小键盘设置为用于导航命令,则按数字小键盘上的逗号键确实可以作为删除命令。但是,我需要获取 NORMAL DELETE 键的字符串。我该怎么做?
【问题讨论】:
标签: delphi keyboard-shortcuts delphi-10.4-sydney