Share via


InjectedInputMouseInfo Class

Definition

Represents programmatically generated mouse input.

public ref class InjectedInputMouseInfo sealed
/// [Windows.Foundation.Metadata.Activatable(196608, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 196608)]
class InjectedInputMouseInfo final
[Windows.Foundation.Metadata.Activatable(196608, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 196608)]
public sealed class InjectedInputMouseInfo
function InjectedInputMouseInfo()
Public NotInheritable Class InjectedInputMouseInfo
Inheritance
Object Platform::Object IInspectable InjectedInputMouseInfo
Attributes

Windows requirements

Device family
Windows 10 Anniversary Edition (introduced in 10.0.14393.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v3.0)

Examples

The following example shows how to inject basic mouse input.

  1. Create an instance of an InputInjector object by calling its static TryCreate method and use the InputInjector.InjectMouseInput method to set up for the mouse input.

    InjectedInputMouseInfo inputInfo = new InjectedInputMouseInfo();
    InputInjector inputInjector = InputInjector.TryCreate();
    inputInjector.InjectMouseInput(new[] { inputInfo });
    
  2. Initiate mouse input through the InjectedInputMouseInfo class using InjectedInputMouseOptions to specify the input action. Here we use the DeltaX and DeltaY properties to move the mouse pointer to the right 20 pixels and down 20 pixels.

    var inputMouseInfo = new InjectedInputMouseInfo();
    InputInjector inputInjector = InputInjector.TryCreate();
    inputInjector.InjectMouseInput(new[] { inputMouseInfo });
    
    InjectedInputMouseInfo injectedMouseMove = new InjectedInputMouseInfo
    {
        MouseOptions = InjectedInputMouseOptions.Move,
        DeltaX = 20,
        DeltaY = 20
    };
    
    inputInjector.InjectMouseInput(new[] { injectedMouseMove });
    
  3. In this step, we use the LeftDown and LeftUp fields and the MouseOptions property to simulate a mouse click by pressing and releasing the left mouse button.

    var down = new InjectedInputMouseInfo
    {
        MouseOptions = InjectedInputMouseOptions.LeftDown
    };
    
    var up = new InjectedInputMouseInfo
    {
        MouseOptions = InjectedInputMouseOptions.LeftUp
    };
    
    inputInjector.InjectMouseInput(new[] { down, up });
    
  4. Finally, we show how to use the Wheel field and the MouseData property to simulate a negative mouse wheel rotation of three detents.

    var mouseWheelDetent = -360;
    
    var injectedMouseWheelDetent = new InjectedInputMouseInfo
    {
        MouseOptions = InjectedInputMouseOptions.Wheel,
        MouseData = (uint)mouseWheelDetent
    };
    
    inputInjector.InjectMouseInput(new[] { injectedMouseWheelDetent });
    

Here are some other downloadable samples that demonstrate basic input and input injection:

Remarks

Important

The APIs in this namespace require the inputInjectionBrokered restricted capability to be declared in the application manifest. For more information on app capability requirements, see App capability declarations.

To use the input injection APIs, open the Package.appxmanifest file and add the following (the rescap namespace hosts the restricted capabilities, whuch lets you declare the inputInjectionBrokered capability in the Capabilities section).

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

Constructors

InjectedInputMouseInfo()

Creates a new InjectedInputMouseInfo object that is used to specify the mouse input to inject.

Properties

DeltaX

Gets or sets the change in the x-coordinate value of the mouse cursor.

DeltaY

Gets or sets the change in the y-coordinate value of the mouse cursor.

MouseData

Gets or sets a value used by other properties (see MouseOptions).

MouseOptions

Gets or sets the various options, or modifiers, used to simulate mouse input.

TimeOffsetInMilliseconds

Gets or sets the baseline, or reference value, for timed input events such as a double click/tap.

Applies to

See also