【问题标题】:XAML touch events don't workXAML 触摸事件不起作用
【发布时间】:2015-01-23 12:16:04
【问题描述】:

我正在使用 c++(DirectX 和 XAML 应用程序)开发 windows8.1 游戏。而且我发现在我的游戏中处理触摸的问题很少。我正在使用这些事件处理程序来检测用户触摸/点击。

// The CoreIndependentInputSource will raise pointer events for the specified device types on whichever thread it's created on.
    m_coreInput = swapChainPanel->CreateCoreIndependentInputSource(
        Windows::UI::Core::CoreInputDeviceTypes::Mouse |
        Windows::UI::Core::CoreInputDeviceTypes::Touch |
        Windows::UI::Core::CoreInputDeviceTypes::Pen
        );

    // Register for pointer events, which will be raised on the background thread.
    m_coreInput->PointerPressed += ref new TypedEventHandler<Object^, PointerEventArgs^>(this, &OpenGLESPage::OnPointerPressed);
    m_coreInput->PointerMoved += ref new TypedEventHandler<Object^, PointerEventArgs^>(this, &OpenGLESPage::OnPointerMoved);
    m_coreInput->PointerReleased += ref new TypedEventHandler<Object^, PointerEventArgs^>(this, &OpenGLESPage::OnPointerReleased);

....

void OpenGLESPage::OnPointerReleased(Platform::Object^ sender, PointerEventArgs^ e)
{
    e->Handled = true;
    Windows::UI::Input::PointerPoint ^ point = e->CurrentPoint;
    ....
}

如果我按下鼠标单键 - 一切正常,所有事件都将被触发 - 按下、移动、释放。但如果我执行这种组合 - 事件将不会被正确触发。

  1. 按鼠标左键 -> 调试:左按
  2. 按鼠标右键 -> ???调试:移动
  3. 释放鼠标左键 -> ???调试:移动
  4. 释放鼠标右键 -> 调试:释放右键

我错过了什么?我怎样才能让所有处理程序正常工作?

【问题讨论】:

    标签: c++ xaml windows-runtime touch windows-8.1


    【解决方案1】:

    (复制自https://social.msdn.microsoft.com/Forums/windowsapps/en-US/6ce9be89-8b14-46fa-b3d5-622bef0adb81/xaml-touch-events-dont-work-properly?forum=winappswithnativecode

    这听起来像是正确的行为。鼠标是单个指针,而不是单独按钮的单独指针。只要任何按钮按下,指针就被按下,您可以检查状态以查看哪些按钮按下。

    如果您可以解释您实际尝试做的事情,我们或许可以提供更有针对性的帮助。我怀疑您最好在更新循环中查看指针状态,而不是等待指针事件,但这取决于最终目标。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-06
      • 2012-06-17
      • 2020-09-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多