locked
XAML touch events don't work properly

    Question

  • I'm developing windows8.1 game with c++ (DirectX and XAML App). And I have discovered few problems with handling touches in my game. I'm using these event handlers to detect user touches/clicks.

    	// Register our SwapChainPanel to get independent input pointer events
    	auto workItemHandler = ref new WorkItemHandler([this](IAsyncAction ^)
    	{
    		// 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);
    
    		// Begin processing input messages as they're delivered.
    		m_coreInput->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessUntilQuit);
    	});
    
    	// Run task on a dedicated high priority background thread.
    	m_inputLoopWorker = ThreadPool::RunAsync(workItemHandler, WorkItemPriority::High, WorkItemOptions::TimeSliced);
    
    ...
    
    
    void OpenGLESPage::OnPointerPressed(Platform::Object^ sender, PointerEventArgs^ e)
    {
    	e->Handled = true;
    	Windows::UI::Input::PointerPoint ^ point = e->CurrentPoint;
            ....
    }

    If I press single mouse button - everything works fine, all events will be fired - press, move, release. But if I perform this combination - events won't be fired properly.

    1. press left mouse button -> Debug: left pressed
    2. press right mouse button -> ??? Debug: moved
    3. release left mouse button -> ??? Debug: moved
    4. release right mouse button -> Debug: right released

    Why I'm receiving wrong events on step 2 and 3?



    • Edited by sadworf Friday, January 23, 2015 1:42 PM
    Friday, January 23, 2015 1:38 PM

Answers

  • That sounds like correct behaviour. The mouse is a single pointer, not separate pointers for the separate buttons. So long as any button is down the pointer is pressed, and you can check the state to see which buttons are down.

    If you can explain what you are actually trying to do we may be able to provide more directed help. I suspect you'll be best off looking at the pointer state in your update loop rather than waiting for pointer events, but it depends on the ultimate goal.


    Friday, January 23, 2015 4:21 PM
    Moderator