Pointer class

Applies to Windows and Windows Phone

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

In most cases, we recommend that you get pointer info through the event argument of the pointer event handlers in your chosen Windows 8 language framework (Windows Store apps using JavaScript, Windows Store apps using C++, C#, or Visual Basic, or Windows Store apps using DirectX with C++).

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.

The static PointerPoint methods, GetCurrentPoint and GetIntermediatePoints, always use the context of the app.

Inheritance

Object
  Pointer

Syntax


public sealed class Pointer

Attributes

[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]
[WebHostHidden()]

Members

The Pointer class has these types of members:

Methods

The Pointer class inherits methods from the Object class.

Properties

The Pointer class has these properties.

PropertyAccess typeDescription

IsInContact

Read-onlyGets 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

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

PointerDeviceType

Read-onlyGets the PointerDeviceType for the pointer device.

PointerId

Read-onlyGets the system-generated identifier for this pointer reference.

 

Remarks

Pointer is an abstract class that 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.

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


Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml.Input
Windows::UI::Xaml::Input [C++]

Metadata

Windows.winmd

See also

Input sample

 

 

Show:
© 2014 Microsoft. All rights reserved.