• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
5
Question by Alex-Chouls · Nov 20, 2010 at 03:10 AM · editorwindowevent

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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Aubrey Hesselgren · Jan 07, 2011 at 02:31 PM 0
Share

"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.

avatar image absameen · Jul 07, 2012 at 12:50 PM 0
Share

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?

1 Reply

· Add your reply
  • Sort: 
avatar image
14
Best Answer

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!");
 }
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image absameen · Sep 08, 2012 at 09:26 PM 1
Share

Brilliant! I can't believe nobody thought of using Event.current.rawType before; works like a charm!

avatar image TMPxyz · Jul 04, 2014 at 12:46 PM 1
Share

$$anonymous$$an, a true Genius!

avatar image ABerlemont · Aug 11, 2014 at 11:21 PM 2
Share

"you would have to set GUIUtility.hotControl to your control's id"

how ?

avatar image IgorAherne · Jul 17, 2017 at 12:42 AM 0
Share

thank you!! Rewarded +50 rep

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

GUI.Window makes custom EditorWindow drag header unresponsive 2 Answers

EventType.MouseUp seems to dislike buttons 1 Answer

Event.button activating constantly? 0 Answers

How to "paint" objects in the editor? 3 Answers

mouseUp Outside EditorWindow 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges