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.


The APIs in this namespace require the inputInjectionBrokered restricted capability.



Represents programmatically generated gamepad input.


Represents programmatically generated keyboard input, such as a Tab or Shift+Tab (Reverse Tabbing).


Represents programmatically generated mouse input.


Represents programmatically generated pen input.


Represents programmatically generated touch input.


Represents the virtual input device for sending the input data.



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


Contains basic pointer information common to all pointer types.


The offsets, from the injected pointer, for the bounding box that represents the touch contact area.



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


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


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


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


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


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


Specifies the system shortcuts for InjectShortcut.


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


Specifies the type of visual feedback displayed for the injected input type.


Here's an example of a touch input injection function.

First, we call TryCreate to instantiate the InputInjector object.

Then, we call InitializeTouchInjection with an InjectedInputVisualizationMode of Default.

After calculating the point of injection, we call InjectedInputTouchInfo to initialize the list of touch points to inject (for this example, we create one touch point corresponding to the mouse input pointer).

Finally, we call InjectTouchInput twice, the first for a pointer down and the second for a pointer up.

/// <summary>
/// Inject touch input on injection target corresponding 
/// to mouse click on input target.
/// </summary>
/// <param name="pointerPoint">The mouse click pointer.</param>
private void InjectTouchForMouse(PointerPoint pointerPoint)
    // Create the touch injection object.
    _inputInjector = InputInjector.TryCreate();

    if (_inputInjector != null)

        // Create a unique pointer ID for the injected touch pointer.
        // Multiple input pointers would require more robust handling.
        uint pointerId = pointerPoint.PointerId + 1;

        // Get the bounding rectangle of the app window.
        Rect appBounds =

        // Get the top left screen coordinates of the app window rect.
        Point appBoundsTopLeft = new Point(appBounds.Left, appBounds.Top);

        // Get a reference to the input injection area.
        GeneralTransform injectArea =

        // Get the top left screen coordinates of the input injection area.
        Point injectAreaTopLeft = injectArea.TransformPoint(new Point(0, 0));

        // Get the screen coordinates (relative to the input area) 
        // of the input pointer.
        int pointerPointX = (int)pointerPoint.Position.X;
        int pointerPointY = (int)pointerPoint.Position.Y;

        // Create the point for input injection and calculate its screen location.
        Point injectionPoint =
            new Point(
                appBoundsTopLeft.X + injectAreaTopLeft.X + pointerPointX,
                appBoundsTopLeft.Y + injectAreaTopLeft.Y + pointerPointY);

        // Create a touch data point for pointer down.
        // Each element in the touch data list represents a single touch contact. 
        // For this example, we're mirroring a single mouse pointer.
        List<InjectedInputTouchInfo> touchData =
            new List<InjectedInputTouchInfo>
                new InjectedInputTouchInfo
                    Contact = new InjectedInputRectangle
                        Left = 30, Top = 30, Bottom = 30, Right = 30
                    PointerInfo = new InjectedInputPointerInfo
                        PointerId = pointerId,
                        PointerOptions =
                        InjectedInputPointerOptions.PointerDown |
                        InjectedInputPointerOptions.InContact |
                        TimeOffsetInMilliseconds = 0,
                        PixelLocation = new InjectedInputPoint
                            PositionX = (int)injectionPoint.X ,
                            PositionY = (int)injectionPoint.Y
                Pressure = 1.0,
                TouchParameters =
                    InjectedInputTouchParameters.Pressure |

        // Inject the touch input. 

        // Create a touch data point for pointer up.
        touchData = new List<InjectedInputTouchInfo>
            new InjectedInputTouchInfo
                PointerInfo = new InjectedInputPointerInfo
                    PointerId = pointerId,
                    PointerOptions = InjectedInputPointerOptions.PointerUp

        // Inject the touch input. 

Here are some downloadable samples demonstrating basic input and input injection:


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

  • To <Package>
    • xmlns:rescap=""
    • IgnorableNamespaces="rescap"
  • To <Capabilities>
    • <rescap:Capability Name="inputInjectionBrokered" />

See also