Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question: Mouse Dragging stops responding outside Client Area?

Discussion in 'Immediate Mode GUI (IMGUI)' started by IzzySoft, Jan 29, 2016.

  1. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    Hi all,

    When dragging the Scrollbar thumb, while in the Game View it works, even if the cursor goes outside the Game View area, you can see the thumb move up or down depending where you move the cursor. I'm using Event.current from OnGUI().



    When building the executable, and try to drag the Thumb and the cursor leaves the client are, the dragging Halts.
    Is this by design? How can I force it to work like it did in the Game View, does a setting need to be enabled?

    Thanks for any info. :)
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,226
    Yes it is by design. OnGUI does not receive mouse events when the mouse is outside of the window. This is because windows does not send mouse move events to the window when the mouse is outside. A possible solution would be to use Input.mousePosition which is still updated and clamped to the window dimensions.

    More details here
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms645616(v=vs.85).aspx
     
  3. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    Thanks Karl for the reply.

    Just looking through the MSDN, I gather the way Unity does this is with SetCapture()?
    ex: https://msdn.microsoft.com/en-us/library/windows/desktop/gg153550(v=vs.85).aspx

    It sure would be nice if this was natively hacked in someday. ;)
    Event.current.BeginMouseCapture(...);
    Event.current.EndMouseCapture();

    Thanks again,
    Izzy.
     
    Last edited: Feb 18, 2016