KeySequence

I’ve written a small utility package, and can link to the code if anyone is interested. Any input is welcome. I will put up a link to the actual code within the next few days.

The utility package provides a few classes that make it easy to call a block of code once a particular keystroke sequence is executed.
A simple example would be something like:

  • User holds LControl , D : This toggles a debug mode

A more complex example would be:
-User holds LControl , D, then presses num pad keys 1 , 2, 5, 5, 6 then presses return.

If the user lets go of a hold key, or presses the numbers out of sequence, it will not execute.

The following is a working examples of how the code is used.
[java]
KeySequence keySequence = new KeySequence(“Toggle Debug On Object 14.”,
new KeySequenceType(KeyInput.KEY_LCONTROL, SequenceType.HELD),
new KeySequenceType(KeyInput.KEY_D, SequenceType.HELD),
new KeySequenceType(KeyInput.KEY_NUMPAD1, SequenceType.PRESSED),
new KeySequenceType(KeyInput.KEY_NUMPAD4, SequenceType.PRESSED),
new KeySequenceType(KeyInput.KEY_NUMPADENTER , SequenceType.TERMINAL));

    KeystrokeSequence ks = new KeystrokeSequence(inputManager, Arrays.asList(keySequence));
    
    ks.callbacks.add(new KeystrokeSequence.Callback() {

        @Override
        public void run() {
            debugSubSystem.toggleDebug(14);
        }
    });[/java]  

You are able to add multiple KeySequence objects to a KeystrokeSequence. You are also able to add multiple callback objects. Therefore multiple Key Sequences can trigger a Callback, or a set of multiple Callbacks, which can be added or removed at run time.

I also plan on expanding this package to allow for a SequenceType.RELEASED type. This would allow for something like "user holds control, presses 4, 4, 5, then releases control.

3 Likes
2 Likes