house fly

JSwat Project

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 either at the action source code or by looking in the resources/JSwat.properties file. Say the action is the exit action, which is amazingly called 'exit'. To add a keyboard shortcut, or accelerator, to this action we simply add a new option to the resources/JSwat.preferences file, under the 'keys' group. That option is defined like so:

    option text [
      label "Exit program"
      name exit
      value F3
    ]

As you can see here, the option is in the form of a text field. It has a descriptive label and the name is the same as that of the action. The value is the keyboard shortcut itself. That's all there is to it.

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"


Back