2

I'm using a TActionManager, where each action has a keyboard ShortCut assigned to it. I would like to display text which represents the keyboard shortcut to the user. For example, F4 or Ctrl+F or Ctrl+Shift+S. However, the TShortCut is defined as:

type
  TShortCut = Low(Word)..High(Word);

How can I obtain a user-readable string which represents the shortcut assigned to an action?

Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
  • 1
    This is well documented: http://docwiki.embarcadero.com/Libraries/en/System.Classes.TShortCut – David Heffernan Aug 17 '15 at 07:05
  • @David This appears to be a case of documentation not matching - I was looking in the docs matching my Delphi version (even though it should apply for all versions since it existed) - the XE7 docs mention nothing like the XE8 docs do: http://docwiki.embarcadero.com/Libraries/XE7/en/System.Classes.TShortCut – Jerry Dodge Aug 17 '15 at 14:00
  • 1
    True. But you are but a single link away from the topic that has the information. Follow the link to http://docwiki.embarcadero.com/Libraries/XE7/en/Vcl.Menus.ShortCut – David Heffernan Aug 17 '15 at 14:26

1 Answers1

5

I'm answering my own question Q/A style.

There's a built-in function for this called ShortCutToText() which converts any given TShortCut into a readable representation. On the other hand, there's also TextToShortCut() which works the other way around, converting any string into a TShortCut, given it's a valid shortcut value.

Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
  • 1
    The functions exist in [unit `Vcl.Menus`](https://docwiki.embarcadero.com/Libraries/Sydney/en/Vcl.Menus.ShortCutToText), they're not built-in like i.e. `System.SetLength()`. – AmigoJack Feb 02 '22 at 11:35