- Home /
Detecting MouseUp event when the mouse is not over an EditorWindow
Apparently an EditorWindow does not receive mouseUp events when the mouse is not over the window.
For example, in my EditorWindow, I start a drag selection on mouseDown and select items on mouseUp. It works fine if I release the mouse over the EditorWindow, but if I move off the window then release, the window never gets the mouseUp event, and I'm stuck in drag selection mode.
Is this expected behaviour? Is there a reliable workaround for this type of scenario?
I guess I could just kill the selection if the mouse moves off the window, but that's not what the user expects.
"I guess I could just kill the selection if the mouse moves off the window, but that's not what the user expects."
This is what I've done. It's atleast better than getting something stuck to your mouse when there's no drag-outside-window ability.
An honest restriction is better than a false freedom. Better to be honest about your interface affordances than to imply them, and not cater to them.
I'm also interested in this. Is there no way to check whether the mouse is up or down when it is not over an EditorWindow?
It seems that GUI components such as a scrollbar respond to mouseUp and mouseDown even when the mouse is not over its EditorWindow. Surely there must be a way?
Answer by Flipbookee · Sep 08, 2012 at 06:16 PM
I was facing the same problem, and I finally found a solution that works for me, and hopefully would work for you as well.
Contrary to what you may believe, Event.type doesn't just simply return the event's type but among other things it filters out events of type MouseDown, MouseUp, DragPerformed, and DragUpdated and returns EventType.Ignore for the events happened outside of the current clipping region. This seems to be useful to make your window ignore mouse events happening outside of its client area or outside of a scroll view, but it's certainly wrong in cases such these when MouseUp events get ignored.
Luckily, there's a way to bypass this filtering using the Event.rawType property which simply returns the actual type of the event. So to handle MouseUp event you would have to set GUIUtility.hotControl to your control's id on MouseDown and then catch the MouseUp with something like
if (GUIUtility.hotControl == myControlID && Event.current.rawType == EventType.MouseUp)
{
Debug.Log("Yeah! MouseUp!");
}
Brilliant! I can't believe nobody thought of using Event.current.rawType before; works like a charm!
"you would have to set GUIUtility.hotControl to your control's id"
how ?
Your answer
Follow this Question
Related Questions
Detect Enter Key Event with GUILayout.TextField Focused 1 Answer
How can I hide function in Animation Event Window? 0 Answers
EditorWindow.focusedWindow.SendEvent crashes Unity. 1 Answer
Generic Unity Event triggered from Runtime with listener added in Custom Unity Editor 0 Answers
Detect mouse up or end of drag on any scene object 0 Answers