在Kinect SDK 1.7中移交按钮事件

时间:2013-04-05 17:44:02

标签: wpf xaml kinect kinect-sdk

我正在使用Kinect SDK 1.7创建一个WPF应用程序,我需要计算用户放置按钮的次数(不推,只放置)。我发现只有一个事件负责按下XAML中的按钮

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

我无法找到哪个事件负责将手放在按钮上(如果此事件存在)。也许你已经知道哪个事件会这样做?或者如何以另一种方式解决这个问题?

2 个答案:

答案 0 :(得分:2)

KinectTileButton支持手形光标的跟随事件,可以根据您的愿望订阅并采取行动:

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

InitializeKinectButtonBase函数设置按钮的默认行为:

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

您可以在UI中实际定义按钮的任何位置执行相同操作。挂钩HandPointerEnterHandPointerLeave处理程序,然后您可以计算用户将手形光标移入和移出该区域的次数。

答案 1 :(得分:0)

不确定这些是否是自定义控件,但我非常肯定大多数控件都应该带有鼠标输入事件或者能够扩展它。

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

只需让你的方法为每只鼠标增加一个变量。