Search code examples
c#wpfkinect

Kinect 2 onHover click


I am working on a Kinect application for WPF (Kinect 2). I am using the KinectRegion to trigger some buttons, but i want to trigger the buttons on hover and not on click. what is the best way to achieve this? I have tried with MouseEnter and MouseLeave with no luck. My goal is that when the user hovers on a button an animation is played and then after 2 seconds the buttons is clicked. I would appreciate any help!

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

Solution

  • UPDATE -

    Looking for multiple ways to solve this i came up with this solution:

    We executed the code on window load.

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

    Noticed that the mouse pointer does not have the exact same position of the handpointer, i have tested that with negative results. Thats why i placed the mouse pointer slightly left to the handpointer (80 pixs to be exact). You can play around depending on your project. Finally we hide the mouse pointer with the following code:

    this.Cursor = Cursors.None;
    

    Now we can use the OnMouseEnter and OnMouseLeave events...I hope this helps anyone having this problem.