MenuItem.ShortcutKey

From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Design Property (as String)

This MenuItem property can only be set in the Inspector and is not available in code.

The shortcut key for the menu item. If this key and the selected modifier keys are held down, the event handler for the menu item will be executed as if the MenuItem itself were chosen via the mouse pointer.

Notes

When you use the Inspector for the Menu Editor, you specify the menu item's shortcut key by assigning a key to the Key property and (normally) at least one modifier key. The Menu Editor translates your settings into the value for the Shortcut property.

You can use either a printable key or the following non-printable keys as shortcut keys: F1-F15, Tab, Enter, Space, Del (Delete), Return, Bksp (Backspace), Esc, Clear, PageUp, PageDown, Left, Right, Up, Down, Help, and Ins (Insert).

Specifying a Shortcut in Code

To set the shortcut in code, use the MenuItem.Shortcut property. If the shortcut key is more than one character and it is being set via code, the modifier key is not implied and must be explicitly defined. For example, the following line sets the Tab key as the shortcut key and uses the Ctrl key as the modifier.

SpecialMyMenuItem.Shortcut = "Ctrl-Tab"

For macOS, use "Cmd" instead of "Ctrl." Or set the HasStandardModifierKey property to True in the IDE and pass the string literal for the desired keyboard shortcut.