Windows.UI.Input.Preview.Injection 名前空間

キーボード、マウス、タッチ、ペン、ゲームパッドなど、さまざまなデバイスからの入力をプログラムで生成および自動化するためのサポートを提供します。

重要

この名前空間の API には、inputInjectionBrokered の制限付き機能が必要です。

クラス

InjectedInputGamepadInfo

プログラムによって生成されたゲームパッド入力を表します。

InjectedInputKeyboardInfo

Tab キーや Shift キーを押しながら Tab キーを押す (タブの反転) など、プログラムによって生成されたキーボード入力を表します。

InjectedInputMouseInfo

プログラムによって生成されたマウス入力を表します。

InjectedInputPenInfo

プログラムによって生成されたペン入力を表します。

InjectedInputTouchInfo

プログラムによって生成されたタッチ入力を表します。

InputInjector

入力データを送信するための仮想入力デバイスを表します。

構造体

InjectedInputPoint

デバイスに依存しないピクセル (DIP) 内のポインターの画面座標を格納します。

InjectedInputPointerInfo

すべてのポインター型に共通する基本的なポインター情報が含まれています。

InjectedInputRectangle

タッチ接触領域を表す境界ボックスの、挿入されたポインターからのオフセット。

列挙型

InjectedInputButtonChangeKind

ポインターに関連付けられているボタンの状態の変更を指定します。

InjectedInputKeyOptions

InjectedInputKeyboardInfo を使用して物理キーボードまたは仮想キーボードからの入力をシミュレートするために使用されるさまざまなオプションまたは修飾子を指定します。

InjectedInputMouseOptions

InjectedInputMouseInfo を使用してマウス入力をシミュレートするために使用されるさまざまなオプションまたは修飾子を指定します。

InjectedInputPenButtons

InjectedInputPenInfo を使用してペン入力をシミュレートするために使用するペン オプションを指定します。

InjectedInputPenParameters

InjectedInputPenInfo を使用してペン入力をシミュレートするために使用されるペンの状態を指定します。

InjectedInputPointerOptions

InjectedInputMouseInfo、InjectedInputPenInfo、InjectedInputTouchInfo を介してポインター入力をシミュレートするために使用されるさまざまなオプションまたは修飾子を指定します

InjectedInputShortcut

InjectShortcut のシステム ショートカットを指定します。

InjectedInputTouchParameters

InjectedInputTouchInfo を使用してタッチ入力をシミュレートするために使用されるタッチ状態を指定します。

InjectedInputVisualizationMode

挿入された入力の種類に対して表示されるビジュアル フィードバックの種類を指定します。

タッチ入力インジェクション関数の例を次に示します。

まず、TryCreate を呼び出して、InputInjector オブジェクトを初期化します。

次に、DefaultInjectedInputVisualizationModeInitializeTouchInjection を呼び出します。

挿入のポイントを計算した後で、InjectedInputTouchInfo を呼び出して、挿入するタッチ ポイントの一覧を初期化します (たとえば、マウス入力ポインターに対応する 1 つのタッチ ポイントを作成します)。

まず、InjectTouchInput を 2 回呼び出します。1 回目はポインター ダウン用で、2 回目はポインター アップ用です。

/// <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)
    {
        _inputInjector.InitializeTouchInjection(
            InjectedInputVisualizationMode.Default);

        // 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 =
            Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().VisibleBounds;

        // 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 =
            ContainerInject.TransformToVisual(Window.Current.Content);

        // 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 |
                        InjectedInputPointerOptions.New,
                        TimeOffsetInMilliseconds = 0,
                        PixelLocation = new InjectedInputPoint
                        {
                            PositionX = (int)injectionPoint.X ,
                            PositionY = (int)injectionPoint.Y
                        }
                },
                Pressure = 1.0,
                TouchParameters =
                    InjectedInputTouchParameters.Pressure |
                    InjectedInputTouchParameters.Contact
            }
        };

        // Inject the touch input. 
        _inputInjector.InjectTouchInput(touchData);

        // 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. 
        _inputInjector.InjectTouchInput(touchData);
    }
}

基本的な入力と入力の挿入を示すダウンロード可能なサンプルを次に示します。

注釈

入力挿入を使用するには、Package.appxmanifest に以下を追加する必要があります。

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

こちらもご覧ください