CoreIndependentInputSource 类

定义

Surfaces core input API for interoperation scenarios.

public ref class CoreIndependentInputSource sealed : ICoreInputSourceBase, ICorePointerInputSource
public ref class CoreIndependentInputSource sealed : ICoreInputSourceBase, ICorePointerInputSource2
public ref class CoreIndependentInputSource sealed : ICoreInputSourceBase, ICorePointerInputSource2, ICorePointerRedirector
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class CoreIndependentInputSource final : ICoreInputSourceBase, ICorePointerInputSource
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class CoreIndependentInputSource final : ICoreInputSourceBase, ICorePointerInputSource2
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class CoreIndependentInputSource final : ICoreInputSourceBase, ICorePointerInputSource2, ICorePointerRedirector
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class CoreIndependentInputSource : ICoreInputSourceBase, ICorePointerInputSource
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class CoreIndependentInputSource : ICoreInputSourceBase, ICorePointerInputSource2
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class CoreIndependentInputSource : ICoreInputSourceBase, ICorePointerInputSource2, ICorePointerRedirector
Public NotInheritable Class CoreIndependentInputSource
Implements ICoreInputSourceBase, ICorePointerInputSource
Public NotInheritable Class CoreIndependentInputSource
Implements ICoreInputSourceBase, ICorePointerInputSource2
Public NotInheritable Class CoreIndependentInputSource
Implements ICoreInputSourceBase, ICorePointerInputSource2, ICorePointerRedirector
继承
Object IInspectable CoreIndependentInputSource
属性
实现

Windows 要求

设备系列
Windows 10 (在 10.0.10240.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)

示例

初始化独立输入。

// MainPage.cpp
#include "pch.h"
#include "MainPage.h"
#include <winrt/Windows.System.Threading.h>
#include <winrt/Windows.UI.Core.h>
#include <winrt/Windows.UI.Xaml.Controls.h>

using namespace winrt;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;

Windows::Foundation::IAsyncAction m_inputLoopWorker;
...
    // Create a task to register for independent input and begin processing input messages.
    Windows::System::Threading::WorkItemHandler workItemHandler([this](Windows::Foundation::IAsyncAction const& /* action */)
    {
        // The CoreIndependentInputSource will raise pointer events for the specified device types on whichever thread it's created on.
        Windows::UI::Core::CoreIndependentInputSource coreInput{
            MySwapChainPanel().CreateCoreIndependentInputSource(
                Windows::UI::Core::CoreInputDeviceTypes::Mouse |
                Windows::UI::Core::CoreInputDeviceTypes::Touch |
                Windows::UI::Core::CoreInputDeviceTypes::Pen)
        };

        // Register for pointer events, which will be raised on the background thread.
        coreInput.PointerPressed({ this, &MainPage::SCP_OnPointerPressed });
        coreInput.PointerMoved({ this, &MainPage::SCP_OnPointerMoved });
        coreInput.PointerReleased({ this, &MainPage::SCP_OnPointerReleased });

        // Begin processing input messages as they're delivered.
        coreInput.Dispatcher().ProcessEvents(Windows::UI::Core::CoreProcessEventsOption::ProcessUntilQuit);
    });

    // Run task on a dedicated high priority background thread.
    m_inputLoopWorker = Windows::System::Threading::ThreadPool::RunAsync(
        workItemHandler, Windows::System::Threading::WorkItemPriority::High,
        Windows::System::Threading::WorkItemOptions::TimeSliced);
...
void MainPage::SCP_OnPointerPressed(Windows::Foundation::IInspectable const& /* sender */,
    Windows::UI::Core::PointerEventArgs const& /* args */) {}
void MainPage::SCP_OnPointerMoved(Windows::Foundation::IInspectable const& /* sender */,
    Windows::UI::Core::PointerEventArgs const& /* args */) {}
void MainPage::SCP_OnPointerReleased(Windows::Foundation::IInspectable const& /* sender */,
    Windows::UI::Core::PointerEventArgs const& /* args */) {}
// Create a task to register for independent input and begin processing input messages.
auto workItemHandler = ref new WorkItemHandler([this] (IAsyncAction ^)
{
   // The CoreIndependentInputSource will raise pointer events for the specified device types on whichever thread it's created on.
   CoreIndependentInputSource^ coreInput = CreateCoreIndependentInputSource(
      Windows::UI::Core::CoreInputDeviceTypes::Mouse |
      Windows::UI::Core::CoreInputDeviceTypes::Touch |
      Windows::UI::Core::CoreInputDeviceTypes::Pen
   );

   // Register for pointer events, which will be raised on the background thread.
   coreInput->PointerPressed += ref new TypedEventHandler<Object^, PointerEventArgs^>(this, &MyClass::OnPointerPressed);
   coreInput->PointerMoved += ref new TypedEventHandler<Object^, PointerEventArgs^>(this, &MyClass::OnPointerMoved);
   coreInput->PointerReleased += ref new TypedEventHandler<Object^, PointerEventArgs^>(this, &MyClass::OnPointerReleased);

   // Begin processing input messages as they're delivered.
   coreInput->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessUntilQuit);
});

// Run task on a dedicated high priority background thread.
m_inputLoopWorker = ThreadPool::RunAsync(workItemHandler, WorkItemPriority::High, WorkItemOptions::TimeSliced);

有关如何使用 CreateCoreIndependentInputSource 和 CoreIndependentInputSource 的更多示例代码,请参阅 DrawingPanelXAML SwapChainPanel DirectX 互操作示例的类定义。

注解

通过调用 SwapChainBackgroundPanel.CreateCoreIndependentInputSourceSwapChainPanel.CreateCoreIndependentInputSource 创建此类的实例。

CoreIndependentInputSource 类使应用能够处理独立于 XAML UI 线程的输入和呈现,因为你有意在后台线程上提供输入处理逻辑。 必须从非 UI 线程调用 CreateCoreIndependentInputSource ,否则 CreateCoreIndependentInputSource 方法调用将失败。

版本历史记录

Windows 版本 SDK 版本 已添加值
1803 17134 DispatcherQueue

属性

Dispatcher

获取窗口的事件调度程序。

DispatcherQueue

获取与此 CoreIndependentInputSource 关联的 DispatcherQueue

HasCapture

获取一个值,该值报告窗口是否具有指针捕获。

IsInputEnabled

获取或设置一个值,该值指示是否为 UWP 应用启用输入。

PointerCursor

获取或设置应用使用的指针光标。

PointerPosition

获取指针的客户端坐标。

方法

ReleasePointerCapture()

禁用 UWP 应用的指针捕获。

SetPointerCapture()

为 UWP 应用启用指针捕获。

事件

InputEnabled

为 UWP 应用启用或禁用输入时发生。

PointerCaptureLost

当指针移动到另一个 UWP 应用时发生。 此事件是在 PointerExited 之后引发的,是应用为此指针接收的最终事件。

PointerEntered

当指针移动到 UWP 应用的边界框中时发生。

PointerExited

当指针在 UWP 应用的边界框外移动时发生。

PointerMoved

当指针在 UWP 应用的边界框中移动时发生。

PointerPressed

在 UWP 应用的边界矩形内单击鼠标按钮或检测到触摸或笔接触时发生。

PointerReleased

在 UWP 应用的边界矩形内释放鼠标按钮或提升触摸或笔接触时发生。

PointerRoutedAway

当指针重定向到另一个输入对象 (可能在单独的进程中) 时,在接收指针输入的输入对象上发生。

PointerRoutedReleased

在与输入对象关联的所有输入对象上发生,但当前未从中接收输入,该指针在输入对象上触发 CoreIndependentInputSource.PointerReleased 事件。

PointerRoutedTo

在捕获的指针输入之前传递到另一个对象时发生,转换为传递到此对象。

PointerWheelChanged

旋转滚轮按钮时发生。

适用于

另请参阅