Windows.UI.Input.Preview.Injection Windows.UI.Input.Preview.Injection Windows.UI.Input.Preview.Injection Windows.UI.Input.Preview.Injection Namespace

Provides support for programmatically generating and automating input from a variety of devices such as keyboard, mouse, touch, pen, and gamepad.

Note

The APIs in this namespace require the inputInjectionBrokered restricted capability.

Classes

InjectedInputGamepadInfo InjectedInputGamepadInfo InjectedInputGamepadInfo InjectedInputGamepadInfo

Represents programmatically generated gamepad input.

Note

The APIs in this namespace require the inputInjectionBrokered restricted capability.

InjectedInputKeyboardInfo InjectedInputKeyboardInfo InjectedInputKeyboardInfo InjectedInputKeyboardInfo

Represents programmatically generated keyboard input.

Note

The APIs in this namespace require the inputInjectionBrokered restricted capability.

InjectedInputMouseInfo InjectedInputMouseInfo InjectedInputMouseInfo InjectedInputMouseInfo

Represents programmatically generated mouse input.

Note

The APIs in this namespace require the inputInjectionBrokered restricted capability.

InjectedInputPenInfo InjectedInputPenInfo InjectedInputPenInfo InjectedInputPenInfo

Represents programmatically generated pen input.

Note

The APIs in this namespace require the inputInjectionBrokered restricted capability.

InjectedInputTouchInfo InjectedInputTouchInfo InjectedInputTouchInfo InjectedInputTouchInfo

Represents programmatically generated touch input.

Note

The APIs in this namespace require the inputInjectionBrokered restricted capability.

InputInjector InputInjector InputInjector InputInjector

Represents the virtual input device for sending the input data.

Note

The APIs in this namespace require the inputInjectionBrokered restricted capability.

Structs

InjectedInputPoint InjectedInputPoint InjectedInputPoint InjectedInputPoint

Contains the screen coordinates of the pointer in device-independent pixel (DIP).

Note

The APIs in this namespace require the inputInjectionBrokered restricted capability.

InjectedInputPointerInfo InjectedInputPointerInfo InjectedInputPointerInfo InjectedInputPointerInfo

Contains basic pointer information common to all pointer types.

Note

The APIs in this namespace require the inputInjectionBrokered restricted capability.

InjectedInputRectangle InjectedInputRectangle InjectedInputRectangle InjectedInputRectangle

The screen coordinates of the bounding box that represents the touch contact area.

Note

The APIs in this namespace require the inputInjectionBrokered restricted capability.

Enums

InjectedInputButtonChangeKind InjectedInputButtonChangeKind InjectedInputButtonChangeKind InjectedInputButtonChangeKind

Specifies the changes in state of a button associated with a pointer.

Note

The APIs in this namespace require the inputInjectionBrokered restricted capability.

InjectedInputKeyOptions InjectedInputKeyOptions InjectedInputKeyOptions InjectedInputKeyOptions

Specifies the various options, or modifiers, used to simulate input from physical or virtual keyboards through InjectedInputKeyboardInfo.

Note

The APIs in this namespace require the inputInjectionBrokered restricted capability.

InjectedInputMouseOptions InjectedInputMouseOptions InjectedInputMouseOptions InjectedInputMouseOptions

Specifies the various options, or modifiers, used to simulate mouse input through InjectedInputMouseInfo.

Note

The APIs in this namespace require the inputInjectionBrokered restricted capability.

InjectedInputPenButtons InjectedInputPenButtons InjectedInputPenButtons InjectedInputPenButtons

Specifies the pen options used to simulate pen input through InjectedInputPenInfo.

Note

The APIs in this namespace require the inputInjectionBrokered restricted capability.

InjectedInputPenParameters InjectedInputPenParameters InjectedInputPenParameters InjectedInputPenParameters

Specifies the pen states used to simulate pen input through InjectedInputPenInfo.

Note

The APIs in this namespace require the inputInjectionBrokered restricted capability.

InjectedInputPointerOptions InjectedInputPointerOptions InjectedInputPointerOptions InjectedInputPointerOptions

Specifies the various options, or modifiers, used to simulate pointer input through InjectedInputMouseInfo, InjectedInputPenInfo, and InjectedInputTouchInfo.

Note

The APIs in this namespace require the inputInjectionBrokered restricted capability.

InjectedInputShortcut InjectedInputShortcut InjectedInputShortcut InjectedInputShortcut

Specifies the system shortcuts for InjectShortcut.

Note

The APIs in this namespace require the inputInjectionBrokered restricted capability.

InjectedInputTouchParameters InjectedInputTouchParameters InjectedInputTouchParameters InjectedInputTouchParameters

Specifies the touch states used to simulate touch input through InjectedInputTouchInfo.

Note

The APIs in this namespace require the inputInjectionBrokered restricted capability.

InjectedInputVisualizationMode InjectedInputVisualizationMode InjectedInputVisualizationMode InjectedInputVisualizationMode

Specifies the visual feedback modes for input injection.

Note

The APIs in this namespace require the inputInjectionBrokered restricted capability.

Examples

Here, we show how to inject a single touch contact and corresponding pointer up input events.

private void InjectTouch_Button_Click(object sender, RoutedEventArgs e)
{
    InputInjector inputInjector = InputInjector.TryCreate();

    if (inputInjector != null)
    {
        try
        {
            inputInjector.InitializeTouchInjection(
                InjectedInputVisualizationMode.Indirect);

            // Each element in the list represents a single contact.
            // Multiple elements represent multiple contacts. 
            inputInjector.InjectTouchInput(
                new List<InjectedInputTouchInfo>
            {
                new InjectedInputTouchInfo
                {
                    Contact = new InjectedInputRectangle {
                        Top = 50, Bottom = 50, Left = 40, Right = 40 },
                    PointerInfo = new InjectedInputPointerInfo
                    {
                        // PerformanceCount default is 0.
                        // This uses the current tick (or TimeOffsetInMS) in milliseconds. 
                        // The first value passed in becomes a baseline or reference value 
                        // and is treated as a zero time offset. Each subsequent value must 
                        // be larger than the preceeding value. The difference is used
                        // to calculate timed events such as double click events.
                        //
                        // Alternatively, the caller can pass in the value of
                        // QueryPerformanceCounter into the PerformanceCount field.
                        PixelLocation = new InjectedInputPoint
                        {
                            PositionX = 40, PositionY = 50
                        },
                        // PointerID is assigned to a pointer during it’s lifetime in contact with
                        // a touch device. 
                        // The scope of this ID is the InputInjector instance (between a
                        // call to Initialize and the corresponding call to Uninitialize).
                        PointerOptions = InjectedInputPointerOptions.InContact,
                        PointerId = 1
                    },
                    Pressure = 1.0,
                    TouchParameters = 
                    InjectedInputTouchParameters.Pressure | 
                    InjectedInputTouchParameters.Contact
                }
            });
            // Copied from some test tool code...
            System.Threading.Tasks.Task.Delay(100).Wait();

            inputInjector.InjectTouchInput(
                new List<InjectedInputTouchInfo> {
                new InjectedInputTouchInfo {
                    Contact = new InjectedInputRectangle
                    {
                        Top = 50,
                        Bottom = 50,
                        Left = 40,
                        Right = 40
                    },
                    PointerInfo = new InjectedInputPointerInfo {
                        PixelLocation = new InjectedInputPoint {
                            PositionX = 40, PositionY = 50
                        },
                        PointerOptions = InjectedInputPointerOptions.PointerUp,
                        PointerId = 1,
                    },
                    Pressure = 0.0,
                    TouchParameters = 
                    InjectedInputTouchParameters.Pressure | 
                    InjectedInputTouchParameters.Contact
                }
            });
        }
        catch (ArgumentException args)
        {
            // Handle exception.
        }
    }
}

Remarks

Using input injection requires the following be added to the Package.appxmanifest:

  • To <Package>
    • xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
    • IgnorableNamespaces="rescap"
  • To <Capabilities>
    • <rescap:Capability Name="inputInjectionBrokered" />

See Also