Kinect 2 onHover 点击

Kinect 2 onHover click

我正在为 WPF (Kinect 2) 开发一个 Kinect 应用程序。我正在使用 KinectRegion 来触发一些按钮,但我想在悬停时触发按钮,而不是在单击时触发。实现这一目标的最佳方法是什么?我尝试过使用 MouseEnter 和 MouseLeave,但没有成功。我的目标是当用户将鼠标悬停在按钮上时播放动画,然后在 2 秒后单击按钮。如果有任何帮助,我将不胜感激!

<k:KinectRegion x:Name="kinectRegion" >
    <Grid Background="White" Name="gridTest">   

        <k:KinectUserViewer Height="400" Width="300" HorizontalAlignment="Center" VerticalAlignment="Top" DefaultUserColor="#FFF93636" EngagedUserColor="#FF395913" />

        <Button Name="buttonStartSpel" Width="400" Height="200" Margin="0,800,0,0" VerticalAlignment="Top" HorizontalAlignment="Center" Content="Start het spel" Style="{StaticResource KinectCustomButton}" MouseEnter="buttonStartSpel_MouseEnter" MouseLeave="buttonStartSpel_MouseLeave"></Button>

    </Grid>
</k:KinectRegion>

更新 -

寻找多种方法来解决这个问题,我想到了这个解决方案:

我们在 window 加载时执行了代码。

void KinectPointerPointSample_Loaded(object sender, RoutedEventArgs e)
    {
        // Listen to Kinect pointer events
        KinectCoreWindow kinectCoreWindow = KinectCoreWindow.GetForCurrentThread();
        kinectCoreWindow.PointerMoved += kinectCoreWindow_PointerMoved;
    }

    private void kinectCoreWindow_PointerMoved(object sender, KinectPointerEventArgs args)
    {
        KinectPointerPoint kinectPointerPoint = args.CurrentPoint;

        bool isEngaged = kinectPointerPoint.Properties.IsEngaged;

        if (isEngaged)
        {

            System.Drawing.Point mousePt = new System.Drawing.Point((int)(kinectPointerPoint.Position.X * kinectRegion.ActualWidth - 80), (int)(kinectPointerPoint.Position.Y * kinectRegion.ActualHeight));
            System.Windows.Forms.Cursor.Position = mousePt;
        }            

    }

注意到鼠标指针的位置与指针的位置不完全相同,我已经对其进行了测试,但结果为负。这就是为什么我将鼠标指针稍微向左放置到指针(准确地说是 80 像素)。你可以根据你的项目来玩。最后我们用下面的代码隐藏鼠标指针:

this.Cursor = Cursors.None;

现在我们可以使用 OnMouseEnter 和 OnMouseLeave 事件...我希望这对遇到此问题的任何人有所帮助。