Share via


Pointer Class

Definition

Provides basic properties for the input pointer associated with a single mouse, pen/stylus, or touch contact.

public ref class Pointer sealed
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class Pointer final
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class Pointer
Public NotInheritable Class Pointer
Inheritance
Object Platform::Object IInspectable Pointer
Attributes

Examples

The following code example shows the usage of Pointer class to find the unique PointerId of each input contact in an app, use the PointerDeviceType to ignore specific forms of input (for example, mouse input) and store the Pointer positions. For additional code that uses the Pointer class, see the Input sample.

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;
        }
    }
}

Remarks

The Pointer class is used to describe an input device. This class identifies the input device (such as stylus, finger, or mouse) for each pointer event that occurs.

In most cases, we recommend that you get pointer info through the event argument of the pointer event handlers (see PointerRoutedEventArgs).

If the event argument doesn't intrinsically expose the pointer details required by your app, you can get access to extended pointer data through the GetCurrentPoint and GetIntermediatePoints methods of PointerRoutedEventArgs. We recommend using these methods as you can specify the context of the pointer data.

Properties

IsInContact

Gets a value that determines whether the pointer device was in contact with a sensor or digitizer at the time that the event was reported.

IsInRange

Gets a value that indicates whether the pointer device is within detection range of a sensor or digitizer.

PointerDeviceType

Gets the PointerDeviceType for the pointer device.

PointerId

Gets the system-generated identifier for this pointer reference.

Applies to

See also