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, InjectedInputPenInfoInjectedInputTouchInfo를 통해 포인터 입력을 시뮬레이션하는 데 사용되는 다양한 옵션 또는 한정자를 지정합니다.

InjectedInputShortcut

InjectShortcut에 대한 시스템 바로 가기를 지정합니다.

InjectedInputTouchParameters

InjectedInputTouchInfo를 통해 터치 입력을 시뮬레이션하는 데 사용되는 터치 상태를 지정합니다.

InjectedInputVisualizationMode

삽입된 입력 형식에 대해 표시되는 시각적 피드백의 유형을 지정합니다.

예제

다음은 터치 입력 주입 함수의 예입니다.

먼저 TryCreate를 호출하여 InputInjector 개체를 인스턴스화합니다.

그런 다음 InitializeTouchInjectionDefaultInjectedInputVisualizationMode로 호출합니다.

삽입 지점을 계산한 후 InjectedInputTouchInfo를 호출하여 삽입할 터치 지점 목록을 초기화합니다. 이 예에서는 마우스 입력 포인터에 해당하는 한 터치 지점을 만듭니다.

마지막으로, InjectTouchInput을 첫 번째는 포인터 아래로, 두 번째는 포인터 위로 두 번 호출합니다.

/// <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" />

추가 정보