KeyboardShortcuts for a custom node event

Hello,
we are currently adding keyboard shortcuts to our treeengine by using the approach described in the documentation.

For a custom node event I have the following entry in the KeyboardShortcut Array:

{
        keyCombinations: [
            {
                modifierKeys: [KeyboardShortcut.ModifierKey.Alt],
                eventCode: KeyCode.CODE_Z
            }
        ],
        target: {
            type: KeyboardShortcut.TargetType.NODE_EVENT_ACTION,
            event: OPEN_DOCUMENT_EVENT
        },
        label: "Alt + Z"
},

But if I try it in the application it doesn’t seam to work. I test it like this: With the TAB I navigate to the specific node/row and press the key combination.
Do I test wrong, or is my implementation wrong?

Thanks in advance and best regards

Your configuration is correct: a NODE_EVENT_ACTION target is identified by the event field of the action. However, a shortcut can only trigger a node action that is modelled for the focused node, because it ends in the same handler as a click on the row action button.

Therefore the first check is whether you can trigger the action with the mouse, either as a row action button or through the right-click context menu. If you cannot, then OPEN_DOCUMENT_EVENT is either not modelled as an event action on that node type, or the constant does not resolve to exactly the event string of the modelled action.

To separate the two failing cases, add stopIfUnavailable: true to the shortcut. A modelled but hidden or disabled action then shows a warning toast, whereas an unmodelled one stays silent even with the flag set.

See Handling Keyboard Shortcut Events.

Hallo,

I can trigger the action with the mouse and I double checked, that the event used in the TreeModel for that action is the same, that is under OPEN_DOCUMNET_EVENT.
If I add stopIfUnavailable: true nothing changes; so no warning toast is shown

The shortcut never matches, because eventCode is the code property of the KeyboardEvent, which identifies a physical key by its position in the US layout and not by the letter printed on your keyboard. On a German keyboard Y and Z are swapped against that layout. Therefore the key printed Z reports KeyY, while KeyCode.CODE_Z is KeyZ, which is the key printed Y. See Key Combination.

This also explains why stopIfUnavailable: true stays silent. The flag is evaluated only after a shortcut has matched and the modelled action turned out to be hidden or disabled, so a shortcut with a non matching eventCode produces no toast in any case.

You can confirm it in the browser console before changing anything:

document.addEventListener("keydown", (e) => console.log(e.code, e.altKey), true);

Pressing Alt and the key printed Z logs KeyY. Use that code:

keyCombinations: [{ modifierKeys: [KeyboardShortcut.ModifierKey.Alt], eventCode: KeyCode.CODE_Y }]

If your users work with different keyboard layouts, list one entry per physical key, because keyCombinations is an array:

keyCombinations: [
    { modifierKeys: [KeyboardShortcut.ModifierKey.Alt], eventCode: KeyCode.CODE_Y },
    { modifierKeys: [KeyboardShortcut.ModifierKey.Alt], eventCode: KeyCode.CODE_Z }
]

The label is not derived from the layout either, so "Alt + Z" is shown to every user regardless of the keyboard they use. I have reported the documentation gap, because the section warns about Digit4 versus Numpad4 and about the left and right modifier keys, but not about layouts, which is the case that hits a German project first.

Bug ticket was filed.