Overview

A command is any action that can be executed. Commands may be execute primitive logic such as a key press, or they may execute more complex logic such as stating up your media player application. If you can write the code for it, it can be a command.

Included Commands

  • Key Press - Simulates a keypress from the keyboard. The modifiers fields can be used to simulated more complex key presses such as Ctrl Shift Tab.
  • Mouse Click - Simulates a click from one of the mouse buttons Left, Right, or Middle.
  • Mouse Move - A quantified command that moves the mouse to a specified location.
  • Control Mouse - Allows the user to control the mouse position with a joystick.
  • Key Map - Simulates independent key down and key up events dependent on the state of a quantified gesture.
  • Switch - Used to simulate Ctrl/Alt Tab and Ctrl/Alt Shift + Tab key strokes dependent on whether a device delta (such as a scroll wheel on a mouse) is positive or negative.

Extending Commands

Commands can be created by inheriting from the Command abstract class and implementing it's execute method. Quantified commands must also implement the IQuantifiedCommand interface, and accept values from a loosely typed string dictionary. Command properties that can be set by a user through the gui must have the UserPropertyAttribute applied. If the value of a command property is not represented by a primitive type a property converter must be created.

Sample

public class KeyPressCommand : Command
{
    [UserProperty]
    public Keys Key { get; set; }

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

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

    public override void Execute()
    {
        if (Modifier1 != Keys.None)
            KeyboardSimulator.KeyDown(Modifier1);

        if (Modifier2 != Keys.None)
            KeyboardSimulator.KeyDown(Modifier2);

        KeyboardSimulator.KeyPress(Key);

        if (Modifier1 != Keys.None)
            KeyboardSimulator.KeyUp(Modifier1);

        if (Modifier2 != Keys.None)
            KeyboardSimulator.KeyUp(Modifier2);
    }
}

Last edited Dec 2, 2009 at 1:37 AM by PhilipB, version 6

Comments

No comments yet.