共用方式為


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 Platform::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 Interop 範例的類別定義。

備註

呼叫 SwapChainBackgroundPanel.CreateCoreIndependentInputSourceSwapChainPanel.CreateCoreIndependentInputSource來建立這個類別的實例。

CoreIndependentInputSource 類別可讓應用程式處理與 XAML UI 執行緒無關的輸入和轉譯,因為您刻意在背景執行緒上提供輸入處理邏輯。 您必須從非 UI 執行緒呼叫 CreateCoreIndependentInputSource ,否則 CreateCoreIndependentInputSource 方法呼叫將會失敗。

版本歷程記錄

Windows 版本 SDK 版本 已新增值
1803 17134 DispatcherQueue

屬性

Dispatcher

取得視窗的事件發送器。

DispatcherQueue

取得與此CoreIndependentInputSource相關聯的DispatcherQueue

HasCapture

取得值,這個值會報告視窗是否有指標擷取。

IsInputEnabled

取得或設定值,這個值表示 UWP app 是否已啟用輸入。

PointerCursor

取得或設定應用程式所使用的指標游標。

PointerPosition

取得指標的用戶端座標。

方法

ReleasePointerCapture()

停用 UWP 應用程式的指標擷取。

SetPointerCapture()

啟用 UWP 應用程式的指標擷取。

事件

InputEnabled

發生于啟用或停用 UWP app 的輸入時。

PointerCaptureLost

當指標移至另一個 UWP 應用程式時發生。 此事件會在 PointerExited 之後引發,而且是應用程式為此指標所接收的最終事件。

PointerEntered

發生于指標移至 UWP 應用程式的周框方塊時。

PointerExited

發生于指標在 UWP app 周框方塊外移動時。

PointerMoved

發生于指標在 UWP app 周框方塊內移動時。

PointerPressed

發生于按一下滑鼠按鍵,或偵測到 UWP app 周框內的觸控或手寫筆接觸時。

PointerReleased

在 UWP app 周框內放開滑鼠按鍵或觸控或手寫筆接觸點時發生。

PointerRoutedAway

當指標重新導向至另一個輸入物件時,會在接收指標輸入的輸入物件上發生 (可能位於個別進程) 。

PointerRoutedReleased

發生在所有與輸入物件相關聯但目前未接收輸入的輸入物件上,該指標會在輸入物件上引發 CoreIndependentInputSource.PointerReleased 事件。

PointerRoutedTo

發生于先前傳遞至另一個物件的擷取指標輸入時,轉換至傳遞至這個物件。

PointerWheelChanged

發生于旋轉滾輪按鈕時。

適用於

另請參閱