How to Add Shortcuts

Adding Shortcuts

Adding keyboard shortcuts to JSwat actions is simple. Find out what the name of the action is by looking at the action source code. Say the action is the exit action, which amazingly enough, is called 'exit'. To add a keyboard shortcut, or accelerator, to this action we simply add a new default to the Defaults.java file in the jswat package.

The other part is a little more involved. The PreferencesAction class must be updated to allow customizing the new keyboard shortcut. I will leave this to the astute developer to figure out (it is pretty obvious).

Shortcut Values

The allowable values for keyboard shortcuts are defined by the javax.swing.KeyStroke().getKeyStroke(String) method. That information is reprinted here for your convenience.

The keystroke string has the following syntax:

     <modifiers>* (<typedID> | <pressedReleasedID>)
     modifiers := shift | control | meta | alt | button1 | button2 | button3
     typedID := typed <typedKey>
     typedKey := string of length 1 giving Unicode character.
     pressedReleasedID := (pressed | released)? key
     key := KeyEvent keycode name, i.e. the name following "VK_".

If typed, pressed or released is not specified, pressed is assumed. The button1, button2, and button3 modifiers refer to the respective mouse buttons. Here are some examples:

     "INSERT"
     "control DELETE"
     "alt shift X"
     "alt shift released X"
     "typed a"