How to register keyboard shortcuts for actions the right way?

Hi guys,

I'm making keyboard shortcuts for certain actions in my plugin, however, it doesn't turn out the way I want.

<!-- Add your actions here -->
<group id="AsciiDoc">
  <group id="TextFormatting" compact="true" description="hello" popup="true" text="AsciiDoc">
          <action id="asciidoc.maketitle" class="org.asciidoc.intellij.actions.asciidoc.MakeTitle"
                  text="Title" description="Make title" >

            <keyboard-shortcut keymap="$default" first-keystroke="ctrl t"/>
            <keyboard-shortcut keymap="Mac OS X" first-keystroke="ctrl t"/>
            <keyboard-shortcut keymap="Mac OS X 10.5+" first-keystroke="ctrl t"/>
.... more actions

First: am I doing this the right way? I used the above from an example I found somewhere, but explicitly mentioning all the keystrokes for all the keymaps sounds a bit verbose. I tried removing the Mac ones, but after that, the keyboard shutcut didn't work anymore.

Secondly, while the keystroke works nicely, IntelliJ itself shows a different shortcut (see attachment): what it does, is that it shows cmd as the modifier key instead of ctrl. How's that possible?



Screen Shot 2014-12-14 at 00.50.47.png

Under Mac OS X, IntelliJ automatically remaps the Ctrl keyboard modiifer from the default keymap to Cmd. This matches the platform conventions: for example, Windows uses Ctrl-C for copy, whereas Mac uses Cmd-C.

So what you're doing here is registering Ctrl-T as the shortcut for your action on Windows, and both Ctrl-T and Cmd-T on Mac. Note that Ctrl-T (Cmd-T on Mac) is the keyboard shortcut for Update Project. I don't think there are any unused shortcuts which use just the Ctrl key as modifier on Windows.


Hi Dmitry,

Thanks for the anwer. I'm a bit confused though.

In the mapping, I have now 2 actions, 1 for bold, 1 for italic.
the bold is mapped using ctrl b, the italic using control i. When I right click, I see that in the menu, both of them appear to be remapped to CMD+b and CMD+i.

However, when I press ctrl b, the action gets triggered. When I press cmd b, IntelliJ says 'Cannot find declaration to go to'.
For the italic, it's even different: cmd i and control i both make the text italic.

So, you're saying ctrl (and control) are both mapped to cmd, which is why it shows like that in the context meny. But when I press the keyboard shorts, it's different?

Confused! ?:|?:|

Thanks, Erik


That's really weird. Maybe you have some leftovers from testing?

The keyboard shortcut parsing is done by the JDK, it treats "control" and "ctrl" as completely equivalent, and our Ctrl to Cmd remapping works with modifier bits, not shortcut text.


Hi Dmitry...

Leftovers from testing? I'm not sure what that means, but I've attached my complete plugin.xml, and this is the only place where I've registered keyboard mappings. As trivial as it sounds, I don't understand what's going on here.