locked
How to Disable Multi-Touch? RRS feed

  • Question

  • I just want to have single touch interaction for my app.  Is there a way to disable multi-touch for an app?

    Thanks

    Thursday, January 31, 2013 3:49 PM

Answers

  • I have a list of controls that the user needs to drag and drop--one control at a time.

    How do I ignore it? Can you please point me to a code snippet or sample?

    Thanks

    Each touch contact will come with a PointerId in the event args. This will be unique across all current touch points.

    When the user starts their first drag operation, you could read and store the PointerId for that operation. During your 'move' handler, compare the pointer id in the event args with the one you have stored...if they don't match, don't do anything.

    • Marked as answer by Aaron Xue Monday, February 4, 2013 7:21 AM
    Thursday, January 31, 2013 8:18 PM
  • I wouldn't try to fiddle with the touch messages here. If the goal is to limit the dragging to one control at a time then limit it to the controls. Once one is moving, don't move the others.

    At the pointer message level you can track the PointerId in PointerPressed and ignore other PointerIds until you get a PointerReleased or PointerCaptureLost:

            uint trackedPointer = 0;
            void MainPage_PointerCaptureLost(object sender, PointerRoutedEventArgs e)
            {
                Debug.WriteLine("PointerCaptureLost");
                trackedPointer = 0;
            }
    
            void MainPage_PointerReleased(object sender, PointerRoutedEventArgs e)
            {
                Debug.WriteLine("PointerReleased");
                if (trackedPointer == e.Pointer.PointerId)
                {
                    trackedPointer = 0;
                }
            }
    
            void MainPage_PointerPressed(object sender, PointerRoutedEventArgs e)
            {
                bool ignorePointer = (trackedPointer != 0) && (trackedPointer != e.Pointer.PointerId);
                
                Debug.WriteLine("PointerPressed: Type:{0} ID:{1} Tracking:{3} Ignore:{2} ", new object[] {e.Pointer.PointerDeviceType,e.Pointer.PointerId, ignorePointer,trackedPointer} );
                if (trackedPointer == 0)
                {
                    trackedPointer = e.Pointer.PointerId;
                }
            }
            
            void MainPage_PointerMoved(object sender, PointerRoutedEventArgs e)
            {
                bool ignorePointer = (trackedPointer != 0) && (trackedPointer != e.Pointer.PointerId);
                Debug.WriteLine("PointerMoved: Type:{0} ID:{1} Tracking:{3} Ignore:{2} ", new object[] { e.Pointer.PointerDeviceType, e.Pointer.PointerId, ignorePointer, trackedPointer });
            }
    

    --Rob

    • Marked as answer by Aaron Xue Monday, February 4, 2013 7:21 AM
    Thursday, January 31, 2013 10:48 PM
    Moderator

All replies

  • You can't disable it, but you can ignore any contacts after the first.

    What is the scenario you are truing to achieve?

    --Rob

    Thursday, January 31, 2013 5:00 PM
    Moderator
  • I have a list of controls that the user needs to drag and drop--one control at a time.

    How do I ignore it? Can you please point me to a code snippet or sample?

    Thanks

    Thursday, January 31, 2013 7:07 PM
  • I have a list of controls that the user needs to drag and drop--one control at a time.

    How do I ignore it? Can you please point me to a code snippet or sample?

    Thanks

    Each touch contact will come with a PointerId in the event args. This will be unique across all current touch points.

    When the user starts their first drag operation, you could read and store the PointerId for that operation. During your 'move' handler, compare the pointer id in the event args with the one you have stored...if they don't match, don't do anything.

    • Marked as answer by Aaron Xue Monday, February 4, 2013 7:21 AM
    Thursday, January 31, 2013 8:18 PM
  • I wouldn't try to fiddle with the touch messages here. If the goal is to limit the dragging to one control at a time then limit it to the controls. Once one is moving, don't move the others.

    At the pointer message level you can track the PointerId in PointerPressed and ignore other PointerIds until you get a PointerReleased or PointerCaptureLost:

            uint trackedPointer = 0;
            void MainPage_PointerCaptureLost(object sender, PointerRoutedEventArgs e)
            {
                Debug.WriteLine("PointerCaptureLost");
                trackedPointer = 0;
            }
    
            void MainPage_PointerReleased(object sender, PointerRoutedEventArgs e)
            {
                Debug.WriteLine("PointerReleased");
                if (trackedPointer == e.Pointer.PointerId)
                {
                    trackedPointer = 0;
                }
            }
    
            void MainPage_PointerPressed(object sender, PointerRoutedEventArgs e)
            {
                bool ignorePointer = (trackedPointer != 0) && (trackedPointer != e.Pointer.PointerId);
                
                Debug.WriteLine("PointerPressed: Type:{0} ID:{1} Tracking:{3} Ignore:{2} ", new object[] {e.Pointer.PointerDeviceType,e.Pointer.PointerId, ignorePointer,trackedPointer} );
                if (trackedPointer == 0)
                {
                    trackedPointer = e.Pointer.PointerId;
                }
            }
            
            void MainPage_PointerMoved(object sender, PointerRoutedEventArgs e)
            {
                bool ignorePointer = (trackedPointer != 0) && (trackedPointer != e.Pointer.PointerId);
                Debug.WriteLine("PointerMoved: Type:{0} ID:{1} Tracking:{3} Ignore:{2} ", new object[] { e.Pointer.PointerDeviceType, e.Pointer.PointerId, ignorePointer, trackedPointer });
            }
    

    --Rob

    • Marked as answer by Aaron Xue Monday, February 4, 2013 7:21 AM
    Thursday, January 31, 2013 10:48 PM
    Moderator
  • Thanks but I tried this approach and it didn't work for me. I'll try to create sample app and share it.

    Monday, February 4, 2013 7:36 AM