[RSS]

How do I have only Shortcut Keys for an Action?

Contributed by; Varun Nischal

Refer this existing document for more details, on where to use following tricks;

Trick #1

  • This is how Action is registered under certain category into NetBeans IDE, don't remove this;
 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
<filesystem>
    <folder name="Actions">
        <folder name="Tools">        
            <file name="org-nvarun-tat-SayCheez.instance"/>
        </folder>
    </folder>
  • See following code, it 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>
  • And, see this code, it 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>
  • Now, by replacing either one of them OR both of them with following code;
    <folder name="Shortcuts">
        <file name="O-F3.shadow">
            <attr name="originalFile" stringvalue="Actions/Tools/org-nvarun-tat-SayCheez.instance"/>
        </file>
    </folder>

Replace "org-nvarun-tat" with your package name, in which SayCheez resides.
  • This lets you assign a Shortcut Key combination for the Action!

Trick #2

  • This code has a shortcut key Alt+F3, which is represented as O-F3.shadow, so this means, if you have some key combination, that uses Alt, then use O, and for each + sign use - ,finally concatenate with the just formed combination with .shadow! If you use Ctrl, then use D and for Shift, use S!

Tips to Remember

  1. Following are some key equivalents used in XML Layer;
    • A to Z (as it is), F1 to F12 (as it is), 0 to 9 (as it is)
    • / as SLASH, \ as BACK_SLASH
    • ; as SEMI_COLON
    • . as PERIOD
    • as QUOTE
  2. These were some of the frequently used keys in Shortcut Key combination, if you want to know some more, you can post a comment over here. I would be glad to help you out!
  3. Note that KeyEvent.VK_* constants define the names of keys, where you replace * with your choice of key. This is taken care of internally by the IDE.
  4. Look into Java Tutorials for more info!

References