In a Delphi 10.4.2 Win32 VCL Application in Windows 10 x64, I use this code to programmatically create a Shortcut STRING for the DELETE key on a popup menu item:
mGalleryDeleteSelected.Caption := mGalleryDeleteSelected.Caption + #9 + MyShortcutToString(VK_DELETE, []) + ' ';
This is the source-code:
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;
However, instead of getting the shortcut string for the normal DELETE key, I get the shortcut string for the (auxiliary?) Comma/Delete key on the Numeric keypad:
As I have a German language Windows, here are the translations:
KOMMA = comma
ZEHNERTASTATUR = numeric keypad
The default Delete key on a German keyboard has the label "entf" (abbreviation for "Entfernen")
The keypress of the comma key on the numeric keypad does work as a Delete command if the numeric keypad is set to work for navigation commands. However, I need to get the string for the NORMAL DELETE key. How can I do that?