Pointer 類別

定義

提供與單一滑鼠、畫筆/手寫筆或觸控接觸點相關聯的輸入指標基本屬性。

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

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

範例

下列程式碼範例顯示 Pointer 類別的使用方式,以尋找應用程式中每個輸入連絡人的唯一 PointerId 、使用 PointerDeviceType 忽略特定形式的輸入 (,例如滑鼠輸入) 並儲存指標位置。 如需使用 Pointer 類別的其他程式碼,請參閱 輸入範例

using System.Collections.Generic;
using Windows.Foundation;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Navigation;

namespace PointerExample
{
    public sealed partial class BlankPage : Page
    {
        Dictionary<uint, Point?> _contacts;
        const uint SUPPORTEDCONTACTS = 5;

        public BlankPage()
        {
            this.InitializeComponent();
            _contacts = new Dictionary<uint, Point?>((int)SUPPORTEDCONTACTS);
            this.PointerPressed += BlankPage_PointerPressed;
            this.PointerReleased += BlankPage_PointerReleased;
        }

        private void BlankPage_PointerPressed(object sender, 
            PointerRoutedEventArgs e)
        {
            // Ignore mouse inputs. 
            if (e.Pointer.PointerDeviceType != 
                Windows.Devices.Input.PointerDeviceType.Mouse)
            {
                // Store and touch input contacts.  
                Windows.UI.Input.PointerPoint pt = e.GetCurrentPoint(this);
                _contacts[e.Pointer.PointerId] = pt.Position;
            }
            e.Handled = true;
        }

        private void BlankPage_PointerReleased(object sender, 
            PointerRoutedEventArgs e)
        {
            // Ignore mouse inputs.
            if (e.Pointer.PointerDeviceType != 
                Windows.Devices.Input.PointerDeviceType.Mouse)
            {
                // Remove pointer contacts information.
                uint ptrId = e.Pointer.PointerId;
                if (_contacts.ContainsKey(ptrId))
                {
                    _contacts[ptrId] = null;
                    _contacts.Remove(ptrId);
                }
            }
            e.Handled = true;
        }
    }
}

備註

在大部分情況下,建議您透過所選語言架構中指標事件處理常式的事件引數取得指標資訊, (使用 JavaScript、使用 C++、C# 或 Visual Basic 的 UWP 應用程式,或使用 DirectX 搭配 C++ 的 UWP 應用程式) 。

如果事件引數未以內部方式公開應用程式所需的指標詳細資料,您可以透過PointerRoutedEventArgsGetCurrentPointGetIntermediatePoints方法來存取擴充指標資料。 建議您使用這些方法,因為您可以指定指標資料的內容。

靜態 PointerPoint 方法 GetCurrentPointGetIntermediatePoints一律使用應用程式的內容。 指標是用來描述輸入裝置的抽象類別。 這個類別會識別每個發生指標事件的輸入裝置 (,例如手寫筆、手指或滑鼠) 。

屬性

IsInContact

取得值,這個值會決定指標裝置在報告事件時是否與感應器或數位板接觸。

IsInRange

取得值,這個值表示指標裝置是否在感應器或數位板的偵測範圍內。

PointerDeviceType

取得指標裝置的 PointerDeviceType

PointerId

取得這個指標參考的系統產生識別碼。

適用於

另請參閱