語言

InputPointerSource 類別

定義

代表一個物件,註冊用來回報指標輸入並提供指標游標及輸入事件處理。

public ref class InputPointerSource sealed : InputObject
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.Foundation.WindowsAppSDKContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class InputPointerSource final : InputObject
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.Foundation.WindowsAppSDKContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class InputPointerSource : InputObject
Public NotInheritable Class InputPointerSource
Inherits InputObject
繼承
Object Platform::Object IInspectable InputObject InputPointerSource
屬性

範例

以下範例展示了如何用 CreateCoreIndependentInputSource 配置 SwapChainPanel,並透過 DispatcherQueueController 在背景執行緒中接收低延遲的筆觸輸入。

void SetupBackgroundPenInput(SwapChainPanel swapChainPanel)
{
    m_dispatcherQueueController = DispatcherQueueController::CreateOnDedicatedThread();

    m_dispatcherQueueController.DispatcherQueue().TryEnqueue([this] {

        InputPointerSourceDeviceKinds deviceKind = (InputPointerSourceDeviceKinds)(
            Microsoft::UI::Input::InputPointerSourceDeviceKinds::Touch |
            Microsoft::UI::Input::InputPointerSourceDeviceKinds::Pen);
        m_coreInput = swapChainPanel().CreateCoreIndependentInputSource(deviceKind);

        m_coreInput.PointerMoved({ this, &DirectXPage::SwapChainPanel_OnPointerMoved });
        });
}


void DirectXPage::SwapChainPanel_OnPointerPressed(InputPointerSource const& sender, Microsoft::UI::Input::PointerEventArgs const& e)
{
    // When the pointer is pressed begin tracking the pointer movement.
    m_main->StartTracking();
}

以下範例展示了如何設定系統手游標影像,使其在游標懸停於 SwapChainPanel 上時顯示:

InputPointerSourceDeviceKinds deviceKind = (InputPointerSourceDeviceKinds)(
    Microsoft::UI::Input::InputPointerSourceDeviceKinds::Touch |
    Microsoft::UI::Input::InputPointerSourceDeviceKinds::Mouse |
    Microsoft::UI::Input::InputPointerSourceDeviceKinds::Pen);
m_coreInput = swapChainPanel().CreateCoreIndependentInputSource(deviceKind);

m_coreInput.InputCursor = InputSystemCursor.Create(InputSystemCursorShape.Hand);

備註

指標事件的座標空間與 SwapChainPanel 物件位於同一座標空間中。

活動順序

正常情況

InputPointerSource 的指標事件在正常情況下遵循保證順序:

  1. 指針進入
  2. 指針按下
  3. 指標已移動
  4. 指標已釋放
  5. PointerExited

其中 PointerMoved 只有在指標移動或滑鼠按鈕狀態改變時才會被提升。 所有事件的指標 ID 相同。

指標捕獲遺失

當輸入系統將接觸中的指標導向到不同的輸入目標時,PointerCaptureLost 會被觸發。 當 PointerCaptureLost 被提出時(只有在收到 PointerPressed 後才會發生),該指標不會再產生其他事件。 具體來說, PointerRelease 和 PointerExited 不會被提出,所以你應該把 PointerCaptureLost 當作某個指標的有效終點狀態來處理。 以下是一個包含失去指標捕獲的有效事件序列範例:

  1. 指針進入
  2. 指針按下
  3. 指標已移動
  4. PointerCapture遺失

路由事件

當輸入系統將接觸中的指標路由到不同的輸入目標時,指標路由事件就會被觸發。 與 PointerCaptureLost 不同,路由事件提供了在釋放指標前,接觸中的指標被路由回去的可能性。

以下顯示一個有效的事件序列,當接觸中的指標被路由到另一個目標,再路由回原始的 InputPointerSource,然後釋放時:

  1. 指針進入
  2. 指針按下
  3. 指標已移動
  4. 指向路由
  5. PointerRoutedTo
  6. 指標已釋放
  7. PointerExited

以下是一個有效的事件序列範例,當接觸中的指標被路由到另一個目標,然後釋放到另一個目標上:

  1. 指針進入
  2. 指針按下
  3. 指標已移動
  4. 指向路由
  5. 指示已路由

Note

當 PointerRoutedRelease 被提出時,該指標不會再產生其他事件。 具體來說, PointerRelease 和 PointerExited 不會被提出,所以你應該把 PointerRoutedReleased 當作某個指標的有效終點狀態來處理。

你也可以收到來自其他目標的新聯絡指標。 在這種情況下,如果指標尚未被當前輸入來源看到, PointerEntered 和 PointerPressed 事件必定會先於 PointerRoutedTo 之前。 以下是這一事件序列的例子:

  1. 指針進入
  2. 指針按下
  3. PointerRoutedTo
  4. 指標已移動
  5. 指標已釋放
  6. PointerExited

屬性

名稱 Description
ActivationBehavior

代表一個物件,註冊用來回報指標輸入並提供指標游標及輸入事件處理。

Cursor

當滑鼠或筆指標位於此 InputPointerSource 的輸入目標上時,會取得或設定顯示的游標。

DeviceKinds

取得這個 InputPointerSource 支援的裝置類型。

DispatcherQueue

取得 InputObject 的 DispatcherQueue 。

(繼承來源 InputObject)

方法

名稱 Description
GetForIsland(ContentIsland)

擷取指定的 ContentIsland 的 InputPointerSource 物件。

GetForVisual(Visual)

代表一個物件,註冊用來回報指標輸入並提供指標游標及輸入事件處理。

GetForWindowId(WindowId)

代表一個物件,註冊用來回報指標輸入並提供指標游標及輸入事件處理。

RemoveForVisual(Visual)

代表一個物件,註冊用來回報指標輸入並提供指標游標及輸入事件處理。

TrySetDeviceKinds(InputPointerSourceDeviceKinds)

代表一個物件,註冊用來回報指標輸入並提供指標游標及輸入事件處理。

事件

名稱 Description
DirectManipulationHitTest

代表一個物件,註冊用來回報指標輸入並提供指標游標及輸入事件處理。

PointerCaptureLost

當與該 InputPointerSource 接觸的指標移動到另一個輸入目標時,會發生這種情況。

PointerEntered

當指標進入該 輸入指標來源的範圍時,會發生這種情況。

PointerExited

當指標移動出此 輸入來源的範圍時,會發生這種情況。

PointerMoved

當指標在該 輸入來源範圍內移動時,會發生這種情況。

PointerPressed

當滑鼠按鍵被按下,或手指或筆開始接觸觸控板表面時,且仍在此 輸入指標源範圍內。

PointerReleased

當先前啟動按鍵動作的指標裝置被放開(滑鼠按鈕被放開,或觸控或筆觸點從數位化器表面移開),且發生在本 輸入指標源範圍內時。

PointerRoutedAway

當指標被重新導向到另一個輸入 指標 源(可能是在另一個程序中)時,會發生這種情況。

PointerRoutedReleased

當原本路由到其他 InputPointerSource 的 s 指標被釋放到另一個輸入目標時,會發生這種情況。

PointerRoutedTo

當指標從不同的輸入目標路由到此 InputPointerSource 時,會發生這種情況。

PointerWheelChanged

當滑鼠滾輪旋轉時發生(滾輪 delta 值改變)。

TouchHitTesting

代表一個物件,註冊用來回報指標輸入並提供指標游標及輸入事件處理。

適用於

另請參閱