如何检查3个手指是否放在屏幕上

时间:2021-09-27 07:02:50

For my application I'd like to use all the built in manipulation possibilities, like e.g. zoom. But if the user presses 3 fingers on the screen I'd like to show a specific UI element. So what is the best way to check if the user has pressed 3 fingers at the same time and next to each other on the screen? (without disabling the built-in manipulation possibilties).

对于我的应用程序,我想使用所有内置的操作可能性,例如放大。但是如果用户在屏幕上按下3个手指,我想显示特定的UI元素。那么检查用户是否同时按下3个手指并且屏幕上彼此相邻的最佳方法是什么? (不禁用内置操作可能性)。

My first approach was to register the TouchDown event on the top Grid element of my layout. In the event handler I get the contact. But what to do there?

我的第一种方法是在我的布局的顶部Grid元素上注册TouchDown事件。在事件处理程序中,我得到了联系人。但那里该怎么办?

Just check if the contact is a fingerprint, store it in a List, and check if the list already contains two similar conacts?

只需检查联系人是否是指纹,将其存储在列表中,并检查列表是否已包含两个类似的联系人?

Or is there a more sexy solution?

还是有更性感的解决方案?

Thanks!

Edit:

Following the answer i wrote two methods:

根据答案我写了两个方法:

private void OnContactDown(object sender, ContactEventArgs e)
        {
            if (this.ContactsOver.Count == 3)
            {
                Console.WriteLine("3 contacts down. Check proximity");

                if (areNear(this.ContactsOver))
                {
                    Console.WriteLine("3 fingers down!");
                }
            }
        }

        private Boolean areNear(ReadOnlyContactCollection contacts)
        {
            if ( Math.Abs(contacts.ElementAt(0).GetCenterPosition(this).X - contacts.ElementAt(1).GetCenterPosition(this).X) < 100 &&
                 Math.Abs(contacts.ElementAt(0).GetCenterPosition(this).Y - contacts.ElementAt(1).GetCenterPosition(this).Y) < 100 &&
                 Math.Abs(contacts.ElementAt(1).GetCenterPosition(this).X - contacts.ElementAt(2).GetCenterPosition(this).X) < 100 &&
                 Math.Abs(contacts.ElementAt(1).GetCenterPosition(this).Y - contacts.ElementAt(2).GetCenterPosition(this).Y) < 100 &&
                 Math.Abs(contacts.ElementAt(0).GetCenterPosition(this).X - contacts.ElementAt(2).GetCenterPosition(this).X) < 100 &&
                 Math.Abs(contacts.ElementAt(0).GetCenterPosition(this).Y - contacts.ElementAt(2).GetCenterPosition(this).Y) < 100)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

They have to be rewritten, but it works. And the threshold (atm 100) has to be adjusted.

它们必须被重写,但它有效。并且必须调整阈值(atm 100)。

1 个解决方案

#1


2  

There is a property on all surface controls that contains the number of contacts över it. The propery is ContactsOver or any variant of it depending on your need, see http://msdn.microsoft.com/en-us/library/microsoft.surface.presentation.controls.surfacecontrol_properties(v=Surface.10).aspx

所有表面控件上都有一个属性,其中包含联系人的数量。根据您的需要,该属性是ContactsOver或其任何变体,请参阅http://msdn.microsoft.com/en-us/library/microsoft.surface.presentation.controls.surfacecontrol_properties(v=Surface.10).aspx

You could check that propery's Count value in your ContactDown event handler for instance. To check their distance, just do a GetPosition on them and use basic vector math on the points.

例如,您可以在ContactDown事件处理程序中检查该属性的Count值。要检查它们的距离,只需对它们执行GetPosition并对点使用基本矢量数学。

#1


2  

There is a property on all surface controls that contains the number of contacts över it. The propery is ContactsOver or any variant of it depending on your need, see http://msdn.microsoft.com/en-us/library/microsoft.surface.presentation.controls.surfacecontrol_properties(v=Surface.10).aspx

所有表面控件上都有一个属性,其中包含联系人的数量。根据您的需要,该属性是ContactsOver或其任何变体,请参阅http://msdn.microsoft.com/en-us/library/microsoft.surface.presentation.controls.surfacecontrol_properties(v=Surface.10).aspx

You could check that propery's Count value in your ContactDown event handler for instance. To check their distance, just do a GetPosition on them and use basic vector math on the points.

例如,您可以在ContactDown事件处理程序中检查该属性的Count值。要检查它们的距离,只需对它们执行GetPosition并对点使用基本矢量数学。