locked
Is there a way to check if the mouse cursor is currently visible?

    Question

  • I’m writing a C++ DirectX / XMAL hybrid for WinRT.  This game is for both mouse and touch.  Currently the system mouse has the behavior I want… shows when using the mouse, hides with touch.

    What I want to do is use my own cursor, but keep the normal behavior of the system mouse for how it hides itself.

    My current plan would be to do the following:

    1. Change the system mouse cursor to a blank image, but leave it there.
    2. Detect when the cursor is showing, and turn on my graphic cursor (and turn it off when the system cursor is not showing.)

    Is there any way to determine that the system mouse cursor is visible or not?  (Again, I want to use the state of the system mouse visibility to turn my own cursor on and off.)

    Thanks,

    Jim Tomasko

    Monday, May 6, 2013 6:49 AM

Answers

  • How different is your custom cursor behavior from the standard behavior? Can you set CoreWindow.PointerCursor to a Custom CoreCursor?

    If you are already monitoring pointer events (e.g. PointerMoved) you can differentiate between Touch, Stylus, and Mouse cursors by checking the PointerEventArgs->CurrentPoint->PointerDevice->PointerDeviceType . You don't need to also handle OnMouseMoved.

    --Rob

    • Marked as answer by HeadRoach Tuesday, May 28, 2013 7:37 AM
    Wednesday, May 15, 2013 1:44 AM
    Owner

All replies

  • Hi,

    As far as I know, there is no directly way to do this. I think you can try to use Pointer capture, you can get CapturePointer or ReleasePointerCapture for some region. Then in PointerCaptures the Pointer.PointerDeviceType property will tell you if it is touch or mouse.

    Please take a look these document
    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.input.pointer.pointerdevicetype.aspx

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

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jesse Jiang Monday, May 13, 2013 6:32 AM
    • Unmarked as answer by HeadRoach Tuesday, May 14, 2013 11:45 PM
    Tuesday, May 7, 2013 3:13 AM
  • Sorry Jesse,

    Capturing the pointer has a long list of baggage associated with it.  Buttons would stop responding if not the captured control as one example.  The Capture is one of the last bastions of "you mess with it, you own it, and deal with it on a control by control basis" left in Windows UI.

    While I'm still working on a solution (I think I'm going to have to ship version 2 with the same system mouse again).

    One thing of promise I've tried is monitoring both MouseDevice::OnMouseMoved as well as the more normal CoreWindow::PointerMoved.

    When OnMouseMoved happens, you always see the mouse appear if it was invisible.  Also, if you ever get PointerMoved, you always see the mouse hide.  I was hoping to use this knowledge to make some sort of switch to turn on and off my mouse (and again, then just have the mouse draw as a no-pixel image.)

    The problem with this is that PointerMoved always follows an OnMouseMoved, so I can't just say "turn my graphic mouse on with PointerMoved, and off with OnMouseMoved... darn.  There are fixes for that problem, such as a timer that won't allow PointerMoved to turn the mouse off for a frame or two after OnMouseMoved... but then there's problems like should the mouse be on or off if my app is snapped into view.  If I end up trying this I'll report if it worked.

     

    Tuesday, May 14, 2013 11:45 PM
  • How different is your custom cursor behavior from the standard behavior? Can you set CoreWindow.PointerCursor to a Custom CoreCursor?

    If you are already monitoring pointer events (e.g. PointerMoved) you can differentiate between Touch, Stylus, and Mouse cursors by checking the PointerEventArgs->CurrentPoint->PointerDevice->PointerDeviceType . You don't need to also handle OnMouseMoved.

    --Rob

    • Marked as answer by HeadRoach Tuesday, May 28, 2013 7:37 AM
    Wednesday, May 15, 2013 1:44 AM
    Owner
  • Thanks Rob, that was exactly what I was missing. 

    The end result of this was another dead end, but a learning experience.  While with your aid I could know when the mouse was moved by touch or mouse, which allowed me to know when to turn my mouse graphics on and off, my graphics lag the actual mouse position quite a bit... appears the position is not updated every composition tick (or whatever that's called... a "game tick").  I guess that's why the recommendation in the docs to use mouse move and relative coordinates to update your own graphics cursor in DirectX.

    I'm left with the realization that a Mouse/Touch handling redesign is in my future that works off relative coordinates.  Thanks to both of you for helping me reach that decision.

    Jim

    Tuesday, May 28, 2013 7:54 AM