Description

Quantified gestures and commands are used for cases when some context is required around the triggering of a command. An example would be a mapping gesture that states that the device position of a device has changed to a command that places the mouse cursor to that position -- the gesture in this case must supply the x and y coordinates of where the device was moved to.

Quantified gestures and commands are implemented via the IQuantifiedGesture and IQuantifiedCommand interfaces. Mapping a gesture that does not supply the required values to a quantified command will put errors into the error log, which can be viewed through the log tab on the gui.

Samples

Gesture

[PartCreationPolicy(CreationPolicy.NonShared)]
[Gesture("ButtonTrackGesture")]
public class ButtonTrackGesture : Gesture, IQuantifiedGesture
{
    ButtonState _oldState;
    String[] _providedValues = new String[] { "ButtonState" };

    [UserProperty]
    public ButtonDeviceComponent Button { get; set; }

    public ButtonTrackGesture()
    {
        _oldState = ButtonState.Up;
    }

    public override Boolean IsGestureActivated()
    {
        if (Button.State == _oldState)
            return false;

        _oldState = Button.State;
        return true;
    }

    public Boolean HasValue(String key)
    {
        return _providedValues.Contains(key);
    }

    public Object GetValue(String key)
    {
        if (key == "ButtonState")
            return Button.State == ButtonState.Up ? false : true;

        throw new ApplicationException();
    }
}

Command

public class KeyMapCommand : Command, IQuantifiedCommand
{
    Boolean _pressed;

    [UserProperty]
    public Keys Key { get; set; }

    public override void Execute()
    {
        if (_pressed)
            KeyboardSimulator.KeyDown(Key);
        else
            KeyboardSimulator.KeyUp(Key);
    }

    String[] _requiredValues = new String[] { "ButtonState" };
    public IEnumerable<String> GetRequiredValues()
    {
        return _requiredValues;
    }

    public void SetValue(String key, Object value)
    {
        if (key == "ButtonState")
            _pressed = (Boolean)value;
    }
}

Last edited Nov 20, 2009 at 8:51 PM by PhilipB, version 4

Comments

No comments yet.