में रहता है:
एक सूचक वस्तु एक एकल, अद्वितीय इनपुट एक इनपुट डिवाइस से इस तरह के एक के रूप में "संपर्क" (एक PointerPoint) (का प्रतिनिधित्व करता है माउस, कलम/स्टाइलस, एकल उंगली, या एकाधिक उंगलियों)। सिस्टम एक पॉइंटर बनाता है जब कोई संपर्क पहले पता लगाया जाता है और जब पॉइंटर पत्तियां (प्रस्थान) पहचान सीमा को छोड़ देता है या रद्द कर देता है तो उसे नष्ट कर देता है। एकाधिक उपकरणों या बहु स्पर्श इनपुट के मामले में, प्रत्येक संपर्क को एक अद्वितीय सूचक के रूप में माना जाता है।
बस एक चेतावनी है, मैं एक मल्टीटच Windows 8 डिवाइस पर इस कोड को परीक्षण करने के लिए नहीं है। इसलिए सिम्युएटर में इसकी सभी सीमाओं के साथ परीक्षण किया गया है, और उपरोक्त लिंक में उल्लेखित विंडोज 8 ने निचले स्तर के कार्यों का उपयोग करने के लिए आपको कई उंगलियों का पता लगाने के लिए इशारा समर्थन में नहीं बनाया है।
सबसे पहले मैंने उपरोक्त एमएसडीएन उदाहरण कोड में दो और शब्दकोश जोड़े और क्लास परिभाषाओं के लिए अपने स्वाइप थ्रेसहोल्ड के लिए दो चर जोड़ा।
Dictionary<uint, Point> startLocation;
Dictionary<uint, bool> pointSwiped;
int swipeThresholdX = 100;
int swipeThresholdY = 100;
मैं तो फार्म के निर्माता में Dictionarys प्रारंभ
startLocation = new Dictionary<uint, Point>((int)SupportedContacts.Contacts);
pointSwiped = new Dictionary<uint, bool>((int)SupportedContacts.Contacts);
तो हर जगह है कि मूल शब्दकोश में जोड़ा गया था या किसी आइटम हटा दिया था मैं नए शब्दकोश के
साथ भी ऐसा ही किया जोड़ने:
startLocation[pt.PointerId] = pt.Position;
pointSwiped[pt.PointerId] = false;
को हटाने:
01,235, startLocation.Remove(pt.PointerId);
pointSwiped.Remove(pt.PointerId);
फिर अंत में उन्हें एक साथ रखा PointerMovedEvent में:
private void targetContainer_PointerMoved(object sender, PointerRoutedEventArgs e)
{
Windows.UI.Input.PointerPoint currentPoint = e.GetCurrentPoint(targetContainer);
if (currentPoint.IsInContact)
{
if (startLocation.ContainsKey(currentPoint.PointerId))
{
Point startPoint = startLocation[currentPoint.PointerId];
if (Math.Abs(currentPoint.Position.X - startPoint.X) > swipeThresholdX) // I only did one Axis for testing
{
pointSwiped[currentPoint.PointerId] = true;
}
}
}
updateInfoPop(e);
}
अंतिम संशोधित MSDN उदाहरण:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace PointerInput
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
Windows.Devices.Input.TouchCapabilities SupportedContacts = new Windows.Devices.Input.TouchCapabilities();
uint numActiveContacts;
Dictionary<uint, Windows.UI.Input.PointerPoint> contacts;
Dictionary<uint, Point> startLocation;
Dictionary<uint, bool> pointSwiped;
int swipeThresholdX = 100;
int swipeThresholdY = 100;
public MainPage()
{
this.InitializeComponent();
numActiveContacts = 0;
contacts = new Dictionary<uint, Windows.UI.Input.PointerPoint>((int)SupportedContacts.Contacts);
startLocation = new Dictionary<uint, Point>((int)SupportedContacts.Contacts);
pointSwiped = new Dictionary<uint, bool>((int)SupportedContacts.Contacts);
targetContainer.PointerPressed += new PointerEventHandler(targetContainer_PointerPressed);
targetContainer.PointerEntered += new PointerEventHandler(targetContainer_PointerEntered);
targetContainer.PointerReleased += new PointerEventHandler(targetContainer_PointerReleased);
targetContainer.PointerExited += new PointerEventHandler(targetContainer_PointerExited);
targetContainer.PointerCanceled += new PointerEventHandler(targetContainer_PointerCanceled);
targetContainer.PointerCaptureLost += new PointerEventHandler(targetContainer_PointerCaptureLost);
targetContainer.PointerMoved += new PointerEventHandler(targetContainer_PointerMoved);
}
// PointerPressed and PointerReleased events do not always occur in pairs.
// Your app should listen for and handle any event that might conclude a pointer down action
// (such as PointerExited, PointerCanceled, and PointerCaptureLost).
void targetContainer_PointerPressed(object sender, PointerRoutedEventArgs e)
{
if (Convert.ToBoolean(SupportedContacts.TouchPresent) && (numActiveContacts > SupportedContacts.Contacts))
{
// cannot support more contacts
eventLog.Text += "\nNumber of contacts exceeds the number supported by the device.";
return;
}
Windows.UI.Input.PointerPoint pt = e.GetCurrentPoint(targetContainer);
// Update event sequence.
eventLog.Text += "\nDown: " + pt.PointerId;
// Change background color of target when pointer contact detected.
targetContainer.Fill = new SolidColorBrush(Windows.UI.Colors.Green);
// Check if pointer already exists (if enter occurred prior to down).
if (contacts.ContainsKey(pt.PointerId))
{
return;
}
contacts[pt.PointerId] = pt;
startLocation[pt.PointerId] = pt.Position;
pointSwiped[pt.PointerId] = false;
++numActiveContacts;
e.Handled = true;
// Display pointer details.
createInfoPop(e);
}
private void targetContainer_PointerEntered(object sender, PointerRoutedEventArgs e)
{
Windows.UI.Input.PointerPoint pt = e.GetCurrentPoint(targetContainer);
// Update event sequence.
eventLog.Text += "\nOver: " + pt.PointerId;
if (contacts.Count == 0)
{
// Change background color of target when pointer contact detected.
targetContainer.Fill = new SolidColorBrush(Windows.UI.Colors.Blue);
}
// Check if pointer already exists (if enter occurred prior to down).
if (contacts.ContainsKey(pt.PointerId))
{
return;
}
// Push new pointer Id onto expando target pointers array.
contacts[pt.PointerId] = pt;
startLocation[pt.PointerId] = pt.Position;
pointSwiped[pt.PointerId] = false;
++numActiveContacts;
e.Handled = true;
// Display pointer details.
createInfoPop(e);
}
// Fires for for various reasons, including:
// - User interactions
// - Programmatic caputre of another pointer
// - Captured pointer was deliberately released
// PointerCaptureLost can fire instead of PointerReleased.
private void targetContainer_PointerCaptureLost(object sender, PointerRoutedEventArgs e)
{
Windows.UI.Input.PointerPoint pt = e.GetCurrentPoint(targetContainer);
// Update event sequence.
eventLog.Text += "\nPointer capture lost: " + pt.PointerId;
if (contacts.ContainsKey(pt.PointerId))
{
checkSwipe();
contacts[pt.PointerId] = null;
contacts.Remove(pt.PointerId);
startLocation.Remove(pt.PointerId);
if (pointSwiped.ContainsKey(pt.PointerId))
pointSwiped.Remove(pt.PointerId);
--numActiveContacts;
}
// Update the UI and pointer details.
foreach (TextBlock tb in pointerInfo.Children)
{
if (tb.Name == e.Pointer.PointerId.ToString())
{
pointerInfo.Children.Remove(tb);
}
}
if (contacts.Count == 0)
{
targetContainer.Fill = new SolidColorBrush(Windows.UI.Colors.Black);
}
e.Handled = true;
}
// Fires for for various reasons, including:
// - A touch contact is canceled by a pen coming into range of the surface.
// - The device doesn't report an active contact for more than 100ms.
// - The desktop is locked or the user logged off.
// - The number of simultaneous contacts exceeded the number supported by the device.
private void targetContainer_PointerCanceled(object sender, PointerRoutedEventArgs e)
{
Windows.UI.Input.PointerPoint pt = e.GetCurrentPoint(targetContainer);
// Update event sequence.
eventLog.Text += "\nPointer canceled: " + pt.PointerId;
if (contacts.ContainsKey(pt.PointerId))
{
checkSwipe();
contacts[pt.PointerId] = null;
contacts.Remove(pt.PointerId);
startLocation.Remove(pt.PointerId);
if (pointSwiped.ContainsKey(pt.PointerId))
pointSwiped.Remove(pt.PointerId);
--numActiveContacts;
}
// Update the UI and pointer details.
foreach (TextBlock tb in pointerInfo.Children)
{
if (tb.Name == e.Pointer.PointerId.ToString())
{
pointerInfo.Children.Remove(tb);
}
}
if (contacts.Count == 0)
{
targetContainer.Fill = new SolidColorBrush(Windows.UI.Colors.Black);
}
e.Handled = true;
}
private void targetContainer_PointerExited(object sender, PointerRoutedEventArgs e)
{
Windows.UI.Input.PointerPoint pt = e.GetCurrentPoint(targetContainer);
// Update event sequence.
eventLog.Text += "\nPointer exited: " + pt.PointerId;
if (contacts.ContainsKey(pt.PointerId))
{
checkSwipe();
contacts[pt.PointerId] = null;
contacts.Remove(pt.PointerId);
startLocation.Remove(pt.PointerId);
if (pointSwiped.ContainsKey(pt.PointerId))
pointSwiped.Remove(pt.PointerId);
--numActiveContacts;
}
// Update the UI and pointer details.
foreach (TextBlock tb in pointerInfo.Children)
{
if (tb.Name == e.Pointer.PointerId.ToString())
{
pointerInfo.Children.Remove(tb);
}
}
if (contacts.Count == 0)
{
targetContainer.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
}
e.Handled = true;
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
void targetContainer_PointerReleased(object sender, PointerRoutedEventArgs e)
{
foreach (TextBlock tb in pointerInfo.Children)
{
if (tb.Name == e.Pointer.PointerId.ToString())
{
pointerInfo.Children.Remove(tb);
}
}
Windows.UI.Input.PointerPoint pt = e.GetCurrentPoint(targetContainer);
// Update event sequence.
eventLog.Text += "\nUp: " + pt.PointerId;
// Change background color of target when pointer contact detected.
targetContainer.Fill = new SolidColorBrush(Windows.UI.Colors.Red);
if (contacts.ContainsKey(pt.PointerId))
{
checkSwipe();
contacts[pt.PointerId] = null;
contacts.Remove(pt.PointerId);
startLocation.Remove(pt.PointerId);
if(pointSwiped.ContainsKey(pt.PointerId))
pointSwiped.Remove(pt.PointerId);
--numActiveContacts;
}
e.Handled = true;
}
private void targetContainer_PointerMoved(object sender, PointerRoutedEventArgs e)
{
Windows.UI.Input.PointerPoint currentPoint = e.GetCurrentPoint(targetContainer);
if (currentPoint.IsInContact)
{
if (startLocation.ContainsKey(currentPoint.PointerId))
{
Point startPoint = startLocation[currentPoint.PointerId];
if (Math.Abs(currentPoint.Position.X - startPoint.X) > swipeThresholdX) // I only did one Axis for testing
{
pointSwiped[currentPoint.PointerId] = true;
}
}
}
updateInfoPop(e);
}
int numberOfSwipedFingers()
{
int count = 0;
foreach (var item in pointSwiped)
{
if (item.Value) { count += 1; }
}
return count;
}
void checkSwipe()
{
int fingers = numberOfSwipedFingers();
if (fingers > 1)
{
eventLog.Text += "\nNumber of Swiped fingers = " + fingers;
}
else if (fingers == 1)
{
eventLog.Text += "\nNumber of Swiped fingers = " + fingers;
}
if(fingers > 0)
pointSwiped.Clear();
}
void createInfoPop(PointerRoutedEventArgs e)
{
Windows.UI.Input.PointerPoint currentPoint = e.GetCurrentPoint(targetContainer);
TextBlock pointerDetails = new TextBlock();
pointerDetails.Name = currentPoint.PointerId.ToString();
pointerDetails.Foreground = new SolidColorBrush(Windows.UI.Colors.White);
pointerInfo.Children.Add(pointerDetails);
pointerDetails.Text = queryPointer(e);
}
void updateInfoPop(PointerRoutedEventArgs e)
{
foreach (TextBlock pointerDetails in pointerInfo.Children)
{
if (pointerDetails.Name == e.Pointer.PointerId.ToString())
{
pointerDetails.Text = queryPointer(e);
}
}
}
String queryPointer(PointerRoutedEventArgs e)
{
Windows.UI.Input.PointerPoint currentPoint = e.GetCurrentPoint(targetContainer);
String details = "";
switch (e.Pointer.PointerDeviceType)
{
case Windows.Devices.Input.PointerDeviceType.Mouse:
details += "\nPointer type: mouse";
break;
case Windows.Devices.Input.PointerDeviceType.Pen:
details += "\nPointer type: pen";
if (e.Pointer.IsInContact)
{
details += "\nPressure: " + currentPoint.Properties.Pressure;
details += "\nrotation: " + currentPoint.Properties.Orientation;
details += "\nTilt X: " + currentPoint.Properties.XTilt;
details += "\nTilt Y: " + currentPoint.Properties.YTilt;
details += "\nBarrel button pressed: " + currentPoint.Properties.IsBarrelButtonPressed;
}
break;
case Windows.Devices.Input.PointerDeviceType.Touch:
details += "\nPointer type: touch";
details += "\nrotation: " + currentPoint.Properties.Orientation;
details += "\nTilt X: " + currentPoint.Properties.XTilt;
details += "\nTilt Y: " + currentPoint.Properties.YTilt;
break;
default:
details += "\nPointer type: n/a";
break;
}
GeneralTransform gt = targetContainer.TransformToVisual(page);
Point screenPoint;
screenPoint = gt.TransformPoint(new Point(currentPoint.Position.X, currentPoint.Position.Y));
details += "\nPointer Id: " + currentPoint.PointerId.ToString() +
"\nPointer location (parent): " + currentPoint.Position.X + ", " + currentPoint.Position.Y +
"\nPointer location (screen): " + screenPoint.X + ", " + screenPoint.Y;
return details;
}
}
}
समस्या के रूप में @Programmer मुझे लगता है कि आप अलग-अलग बिंदुओं पर कई बिंदुओं को जारी कर रहे हैं, आपको शायद मेरे उदाहरण में चेकस्वाइप दिनचर्या पर वापस जाना चाहिए और या तो इसके चारों ओर एक ताला लगा देना चाहिए या अन्य अंगुली रिलीज को तब तक दर्ज करने से रोकने के लिए कुछ और करना चाहिए पहला किया जाता है। दुर्भाग्यवश एम्यूलेटर के साथ मेरे पास दो अंगुलियों को जारी करने के लिए अनुकरण करने का कोई तरीका नहीं है, और वे एक ही समय में हैं। मैं इसे थोड़ा और आगे देखूंगा हालांकि –
@ प्रोग्रामर मैं इसे देख लूंगा, यह एक दिन या उससे भी अधिक हो सकता है। –
क्या आप इस प्रश्न को देख सकते हैं? http://stackoverflow.com/questions/13011920/handling-2-3-4-5-fingers-tapped-doubletap-holding-gestures-in-winrt-app – Elmo