I want to implement a custom code class that uses NamedKeyStrokes. I am trying to use an existing class in my module (VASL) as a model but I cannot understand how it works.
The buildFile entry for the model class (PieceLinker.java) is as follows:
public class PieceLinker extends AbstractConfigurable implements KeyListener, CommandEncoder, GameComponent, Drawable {
[various declarations omitteed]
private NamedKeyStroke linkKey = new NamedKeyStroke("71dd9846"); // CTL+ALT+L
private NamedKeyStroke unlinkKey = new NamedKeyStroke("b385611"); // CTL+ALT+U
The net effect of this (and the rest of the class obviously) is that when CTRL+ALT+L is pressed and two counters are selected, those two counters are linked by a line drawn between them. Pressing CTRL+ALT+U removes the line.
What I cannot understand is how the various inputs are determined and how they link to the desired keystrokes. More specifically:
in the buildFile, LinkKey=“76,650”, what do 76 and 650 represent and how would I know what to use if I want to used CTRL+ALT+S instead of CTRL+ALT+L? Or say SHIFT+L?
in the class code, new NamedKeyStroke(“71dd9846”), what does the 71dd9846 represent and how would I know what to use for a different keystroke?
I can see how the NamedKeyStrokes are used by the class to actually manage the linking and unlinking. I just can’t figure out how the above lines work to create something that responds to the specific CTRL+ALT+L and CTRL+ALT+U keystrokes.
Those are the key code and modifiers, respectively. The key codes are defined in java.awt.event.KeyEvent and modifiers are defined in java.awt.event.InputEvent.
private NamedKeyStroke linkKey = new NamedKeyStroke("71dd9846"); // CTL+ALT+L
That comment at the end is meaningless, it bears no relationship at all to what that piece of code is doing. A NamedKeyStroke can be EITHER a specified real (can be typed)l keystroke OR a virtual named Keystroke. It can’t be both.
So the above fragment is creating a virtual keystroke with the name “71dd9846”. Internally, in Vassal, this will be allocated an invisible Keystroke from a pool that is used by Vassal for all references to the Keystroke named “71dd9846”. This can never respond to CTRL+ALT+L or any other other type-able keystroke.