Hand over button event in Kinect SDK 1.7

为君一笑 提交于 2019-12-20 04:55:38

问题


I am creating a WPF application using Kinect SDK 1.7 and I need to count how many times user place hand over the button (not push, just place over). I found only an event responsible for pushing the button in XAML

<k:KinectTileButton Label="Click" Click="PushButtonEvent"></k:KinectTileButton>

I can't find which event is responsible for placing hand over the button (if this event exists). Maybe you've got some idea which event would do that? Or how to resolve this problem in another way?


回答1:


The KinectTileButton supports the follow events for the hand cursor, which can be subscribed to and acted upon to your desire:

public static readonly RoutedEvent HandPointerMoveEvent = EventManager.RegisterRoutedEvent(
    "HandPointerMove", RoutingStrategy.Bubble, typeof(EventHandler<HandPointerEventArgs>), typeof(KinectRegion));

public static readonly RoutedEvent HandPointerEnterEvent = EventManager.RegisterRoutedEvent(
    "HandPointerEnter", RoutingStrategy.Direct, typeof(EventHandler<HandPointerEventArgs>), typeof(KinectRegion));

public static readonly RoutedEvent HandPointerLeaveEvent = EventManager.RegisterRoutedEvent(
    "HandPointerLeave", RoutingStrategy.Direct, typeof(EventHandler<HandPointerEventArgs>), typeof(KinectRegion));

public static readonly RoutedEvent HandPointerPressEvent = EventManager.RegisterRoutedEvent(
    "HandPointerPress", RoutingStrategy.Bubble, typeof(EventHandler<HandPointerEventArgs>), typeof(KinectRegion));

public static readonly RoutedEvent HandPointerPressReleaseEvent = EventManager.RegisterRoutedEvent(
    "HandPointerPressRelease", RoutingStrategy.Bubble, typeof(EventHandler<HandPointerEventArgs>), typeof(KinectRegion));

public static readonly RoutedEvent HandPointerGripEvent = EventManager.RegisterRoutedEvent(
    "HandPointerGrip", RoutingStrategy.Bubble, typeof(EventHandler<HandPointerEventArgs>), typeof(KinectRegion));

public static readonly RoutedEvent HandPointerGripReleaseEvent = EventManager.RegisterRoutedEvent(
    "HandPointerGripRelease", RoutingStrategy.Bubble, typeof(EventHandler<HandPointerEventArgs>), typeof(KinectRegion));

public static readonly RoutedEvent HandPointerGotCaptureEvent = EventManager.RegisterRoutedEvent(
    "HandPointerGotCapture", RoutingStrategy.Direct, typeof(EventHandler<HandPointerEventArgs>), typeof(KinectRegion));

public static readonly RoutedEvent HandPointerLostCaptureEvent = EventManager.RegisterRoutedEvent(
    "HandPointerLostCapture", RoutingStrategy.Direct, typeof(EventHandler<HandPointerEventArgs>), typeof(KinectRegion));

public static readonly RoutedEvent QueryInteractionStatusEvent = EventManager.RegisterRoutedEvent(
    "QueryInteractionStatus", RoutingStrategy.Bubble, typeof(EventHandler<QueryInteractionStatusEventArgs>), typeof(KinectRegion));

The InitializeKinectButtonBase function sets up the default behavior for the buttons:

private void InitializeKinectButtonBase()
{
    KinectRegion.AddHandPointerPressHandler(this, this.OnHandPointerPress);
    KinectRegion.AddHandPointerGotCaptureHandler(this, this.OnHandPointerCaptured);
    KinectRegion.AddHandPointerPressReleaseHandler(this, this.OnHandPointerPressRelease);
    KinectRegion.AddHandPointerLostCaptureHandler(this, this.OnHandPointerLostCapture);
    KinectRegion.AddHandPointerEnterHandler(this, this.OnHandPointerEnter);
    KinectRegion.AddHandPointerLeaveHandler(this, this.OnHandPointerLeave);

    KinectRegion.SetIsPressTarget(this, true);
}

You can do the same in wherever you are actually defining the button in the UI. Hook the HandPointerEnter and the HandPointerLeave handlers and you can then count how many times a user moves the hand cursor into and out of the region.




回答2:


Not sure if these are custom controls, however I'm quite positive most controls should come with a mouse enter event or be able to extend it.

<Button Tag="Test" MouseEnter="enterMethod">

And just have your method increment a variable for each mouse over.



来源:https://stackoverflow.com/questions/15840187/hand-over-button-event-in-kinect-sdk-1-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!