Keyboard Shortcuts in Standard Buttons


NOTE: Standard UI keyboard shortcuts use Unreal's Enhanced Input system, and assumes knowledge of Input Actions, Triggers and Mapping Contexts - if you are unfamiliar with this, it would be best to read up on it first:

In the Standard UI system, we enable buttons to specify input actions that will act as clicking the button. If the button is enabled and on the screen, pressing the associated key will trigger the button.

This uses Input Icons to display shortcut keys for given input actions.

The buttons can either be assigned bespoke to a given button In WBP_M2_StandardButton /M2_StandardButtonData, or a set of keys can be automatically assigned In button lists.

Note that by default our buttons just listen to the Trigger event, and use that as "Button Clicked". If you want to use shortcut pressed/released events, see Listening to "pressed" or "released".

How to add

Live config

To enable/disable shortcuts in standard UI elements (e.g. the interaction menu and the gadgets' menus), you need the StandardUI.ShortcutsEnabled flag.

In WBP_M2_StandardButton /M2_StandardButtonData

If you have an individual M2_StandardButtonData that you want to assign a keyboard shortcut for (e.g if you are adding a WBP_M2_StandardButton directly to your screen), you can do so by setting the "Shortcuts" data within the object.

The fields are as follows:

  • ShortcutMappingContext and ShortcutAction:

    • These are required for specifying the "Enhanced Input" action and mapping used to identify what key should be pressed.

  • ShortcutIconLeftAligned:

    • This determines whether the shortcut icon appears on the left or the right of the button.

    • NOTE: If left-aligned, the icon is treated as a "visual attachment", so isn't treated as part of the widget when it comes to spacing or the like. This is so that we can have consistently aligned buttons in a list where some buttons don't have icons.

  • ShortcutPrioritizationName and ShortcutPrioritizationPriority:

    • These are optional fields you can add to make your shortcut use the Input Prioritization System (Input Prioritization).

    • (If you don't want to use the Input Prioritization System, leave ShortcutPrioritizationName as None)

    • Note: When using the input prioritization system, you need to make sure the inputs are set to not consume - that way we can listen to all the inputs, and handle them according to their priority

In button lists

If you have a list of buttons, which could have arbitrary buttons in them, but you want to assign a consistent set of shortcuts, you can configure this using the WBP_M2_StandardButtonList

The fields are as follows:

  • ShortcutMappingContext:

    • The mapping used for all the shortcuts in the list.

  • ShortcutActionList:

    • The actions we'll assign to the buttons in the list.

    • If we have more buttons than entries in the list, the surplus buttons won't have shortcut keys.

    • NOTE: If there are shortcuts already assigned in the button data in the list, one of two things will happen:

      • If the shortcuts are one of those already in this list, they will be overridden.

      • If the shortcuts are different actions, they will be ignored. (e.g. if you have actions for E, R, T and Y defined in your ShortcutActionList, but have a button data entry that specifies a "Left click" shortcut, that button will remain, and E, R, T and Y will be assigned to the other buttons in the list.

  • FlipList:

    • Means that we assign the shortcuts from the bottom up, rather than top down. You can use this if you want to have buttons follow a different order stylistically.

  • ShortcutPrioritizationName/ShortcutPrioritizationPriority/LeftAlignShortcutIcons: Same as for M2_StandardButtonData.

Updating the shortcut dynamically

From the button data, you can call UpdateShortcutInfo to update the shortcut info used, e.g. by supplying a new mapping context and input action, or removing the shortcut

Listening to "pressed" or "released"

To use Enhanced Input, we need to map the UI's "clicked", "pressed" and "released" events to Enhanced Input's "trigger types" (Started, Triggered, Ongoing, Canceled, Completed). This cannot be done in a one-size-fits-all way, since the triggers can occur in different ways depending on how the input action is configured.

(E.g. if your input action had no triggers defined, it would do Started = Press, Completed = Release, Triggered = called on tick whilst held. Conversely, if you have the Pressed trigger, then Started, Completed and Triggered are all called when the key is pressed).

By default, we have a single shortcut mapping, from Triggered to the "Clicked" event in the standard button. However, you can enable other events to trigger at the right time for your input action.

For example, the WBP_PartyChatButton uses an input action without a trigger, and instead uses Started and Completed for "pressed" and "released" respectively (but doesn't have a shortcut trigger for "clicked")

The relevant events are as follows:

  • OnActionButtonClicked

  • OnActionButtonPressed

  • OnActionButtonReleased

Last updated