How do I have only shortcut keys for an action?
The New Action wizard allows you to uncheck both menu and toolbar placement for your action and only assign a keyboard shortcut. To learn how to do this manually, read on. Refer to TaT_HackingNetBeansXMLLayerPartOne for more details.
Trick #1
-
Retain the action’s basic registration:
<folder name="Actions">
<folder name="Tools">
<file name="org-nvarun-tat-SayCheez.instance"/>
</folder>
</folder>
-
This registers an action as a Global Menu Item:
<folder name="Menu">
<folder name="Tools">
<file name="org-nvarun-tat-SayCheez.shadow">
<attr name="originalFile"
stringvalue="Actions/Tools/org-nvarun-tat-SayCheez.instance"/>
<attr name="position" intvalue="150"/>
</file>
</folder>
</folder>
-
This registers an action as a Global Toolbar Button:
<folder name="Toolbars">
<folder name="Build">
<file name="org-nvarun-tat-SayCheez.shadow">
<attr name="originalFile"
stringvalue="Actions/Tools/org-nvarun-tat-SayCheez.instance"/>
<attr name="position" intvalue="325"/>
</file>
</folder>
</folder>
-
To assign a shortcut key, replace either or both of them with something like the following:
<folder name="Shortcuts">
<file name="O-F3.shadow">
<attr name="originalFile"
stringvalue="Actions/Tools/org-nvarun-tat-SayCheez.instance"/>
</file>
</folder>
Trick #2
-
In the above example the action has the shortcut key Alt+F3, which is represented as
O-F3. In general, if you have some key combination that uses Alt (or the equivalent on Mac OS X), then useO. Separate modifiers from the base keycode name with-, and append.shadowfor the filename. Ctrl (or its Mac equivalent) is represented byD, and Shift*byS. (CandArepresent the literal *Ctrl and Alt keys, but this is less portable.)
Tips to Remember
-
Following are some keycode equivalents. See Javadoc for
KeyEventfor the full list:-
A to Z (as is), F1 to F12 (as is), 0 to 9 (as is)
-
/ as
SLASH, \ asBACK_SLASH -
; as
SEMI_COLON -
. as
PERIOD -
‘ as
QUOTE
-
See also DevFaqKeybindings.
(Reposted from this entry on NetBeans Zone.)