locked
Proper mouse event handling - PointerPressed, PointerReleased only work with one mousebutton at a time...

    Question

  • Hi guys !

    I currently use the events PointerMoved, PointerReleased, PointerPressed  in my Core::UI::Window to query mouse events in my game.
    Works fine as long as you just press ONE button at a time. A second button press doesn't seem to cast an event.

    1. press the LMB -> PointerPressed is called, cool !
    2. while holding the LMB down, press the RMB -> nothing happens.
    3. releasing the RMB -> nothing happens.
    4. releasing the LMB -> PointerReleased is called.

    Is there maybe another way to query mouse events in WinRT ?
    Or: Can I loop throught the messagequeue on my own without having to rely on the Pointer... Events to be cast ?

    Any help sooo much appreciated,
    Roman

    Saturday, May 19, 2012 7:48 AM

Answers

  • Hi Roman,

    I think Jesse misunderstood your question.

    Mouse events are delivered through the Pointer events. The mouse is a single pointer, not a separate pointer per button, so the first button pushed generates the PointerPressed and the last button released generates the PointerReleased.

    There isn't an event for intermediate changes in the button states. You can poll the current state of a pointer by getting its PointerPoint with the static PointerPoint::GetCurrentPoint(id) and then checking its properties.

    --Rob

    Monday, May 21, 2012 9:38 PM
    Owner
  • Ok, to round this up - You cannot call PointerPoint::GetCurrentPoint(id) until you have a
    valid pointerId. This is achieved by waiting for the first mouse event.

    So now i'm waiting for the first mouse message to occur - store the pointerId and poll
    the mousebutton status from then on via PointerPoint::GetCurrenPointId().


    Roman Pfneudl CEO - vertex4 entertainment ltd.

    • Marked as answer by v4corg Monday, June 11, 2012 5:23 PM
    Monday, June 11, 2012 5:23 PM

All replies

  •  

    Hello,

     

    As far as I know, Pointer events are limited to single-finger interactions such as tap, and they don't support velocity-based interactions. Single finger touches on the screen are converted to an equivalent Windows Runtime pointer event such as PointerPressed

     

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465387.aspx

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, May 21, 2012 9:36 AM
  • Hi Jesse, 

    Thanks for your quick reply.
    Ok, i understand that Pointer events are primary to be used for single-finger interactions.
    But what else can i use to query mouse button - events ?  
    I've read throught anything i could find but i cant seem to find another way of
    querying mouse button events.

    Even Windows::Devices::Input::MouseDevice only handles Mouse movement it seems.

    Is there an alternative way of querying these actions ?

    Cheers,
    Roman


    Roman Pfneudl CEO - vertex4 entertainment ltd.

    Monday, May 21, 2012 2:19 PM
  • Hi Roman,

    I think Jesse misunderstood your question.

    Mouse events are delivered through the Pointer events. The mouse is a single pointer, not a separate pointer per button, so the first button pushed generates the PointerPressed and the last button released generates the PointerReleased.

    There isn't an event for intermediate changes in the button states. You can poll the current state of a pointer by getting its PointerPoint with the static PointerPoint::GetCurrentPoint(id) and then checking its properties.

    --Rob

    Monday, May 21, 2012 9:38 PM
    Owner
  • Hi Rob,

    Thank you, I think that's what I need - But: where to get the pointerId from ?
    If I put in a 0 or a 1 the app crashes with an invalid argument exception.
    The pointerId in the properties I get in the PointerPressed event handler is set to 1.

    Documentation is quite silent about these things. :(

    Thanks,
    Roman


    Roman Pfneudl CEO - vertex4 entertainment ltd.

    Tuesday, May 22, 2012 9:23 AM
  • Ok, to round this up - You cannot call PointerPoint::GetCurrentPoint(id) until you have a
    valid pointerId. This is achieved by waiting for the first mouse event.

    So now i'm waiting for the first mouse message to occur - store the pointerId and poll
    the mousebutton status from then on via PointerPoint::GetCurrenPointId().


    Roman Pfneudl CEO - vertex4 entertainment ltd.

    • Marked as answer by v4corg Monday, June 11, 2012 5:23 PM
    Monday, June 11, 2012 5:23 PM
  • When a mouse button is pressed, you will get a PointerPressed event. From that point on you will not get any PointerPressed or PointerReleased events until ALL mouse buttons have been released. At that point, you will get a PointerReleased event.

    However, you will receive PointerMoved events each time a mouse button is pressed or released. If you look at the CurrentPoint.Properties.PointerUpdateKind of the PointerEventArgs that you receive in the PointerMoved event, it will tell you exactly which button changed, and whether it was pressed or released.

    For concreteness, let's take the example in your question:
    1. press the LMB -> PointerPressed is called, cool !
    2. while holding LMB, press RMB -> a PointerMoved event arrives with its CurrentPoint.Properties.PointerUpdateKind equal to RightButtonPressed
    3. release the RMB -> a PointerMoved event arrives with its CurrentPoint.Properties.PointerUpdateKind equal to RightButtonReleased
    4. release the LMB -> PointerReleased is called.

    Check it out: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.input.pointerupdatekind.aspx


    • Proposed as answer by Tim Abraldes Wednesday, December 19, 2012 1:22 AM
    • Edited by Tim Abraldes Wednesday, December 19, 2012 7:16 PM Adding concrete example
    Wednesday, December 19, 2012 1:21 AM