Add keybord shortcut to custom menu item

I am building a new QuPath extension and I want to add a new menu option to duplicate currently selected annotation. It would be easier for pathologist during annotation time to just quickly duplicate a selected annotation and modify it according to specifications. It can get cumbersome if one needs to always select it from the menu so I want to create a keyboard shortcut with the menu item and I don’t really know how to do it. Currently:

QuPathGUI.addMenuItems(binaryMaskMenu,
                QuPathGUI.createCommandAction(
                        new DuplicateAnnotation(),
                        "Duplicate selected annotation"));

How to do it to work on Windows, Mac and Linux as well? If I set Alt + D in the extension will it be the same for all platforms?

Thanks in advance.

If anyone will look for this in the future, the answer is:

QuPathGUI.addMenuItems(binaryMaskMenu,
                QuPathGUI.createCommandAction(
                        new DuplicateAnnotation(),
                        "Duplicate selected annotation", null,
                        new KeyCodeCombination(KeyCode.D, KeyCombination.CONTROL_DOWN)));

Have you tried Shift + D? There should already be a duplicate annotation command with that shortcut. I use it quite often.

For a full list of shortcuts see https://github.com/qupath/qupath/wiki/Shortcut-keys

2 Likes