Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
1
Question by vexe · Feb 18, 2014 at 03:24 PM · inputeventrect

Detect Ctrl+LMB on a rect in edit mode?

Hello,

I have a Rect called lastRect (which is a rect for an object field), and I want to perform and operation if the user (for example) left click on it while holding the Ctrl key.

I'm not sure how to go about doing that, I tried this:

     if (lastRect != null && lastRect.Contains(Event.current.mousePosition)) {
         if (Event.current.control)
             if (Event.current.button == 0)                
             {
                 isObjectField = !isObjectField;
             }
     }

It didn't seem to work, it gave strange results. For example, if I hold Ctrl and do a left click, the boolean toggles, then if I just hold Ctrl without a LMB, it toggles too!

I think that's not the way to detect input in this case.

I tried caching the current event, and using the local version instead, didn't seem to change much. I also tried using the event (`Event.current.Use()`) when the boolean toggles, didn't do much too (inspector went crazy).

Any ideas?

Thanks!

Comment
Add comment
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

1 Reply

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

Answer by vexe · Feb 19, 2014 at 01:34 PM

Found the solution - with the help of @Jamora

The thing is, if there's no mouse button is pressed, Event.current.button will also return true, that's why holding just control without clicking will return true too.

The trick is to check for the event type first, making sure we get a MouseDown/MouseUp

     if (Event.current.control) {
         if (Event.current.type == EventType.MouseDown) {
             if (Event.current.button == 0) // 0 for LMB, 1 for RMB, 2 for MMB
                   // do whatever...
         }
     }
Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

keyboard event "none" works as "enter" 0 Answers

NSEvents and Unity 0 Answers

Why is this script showing all keycodes except shift? 2 Answers

How can I consume key events to prevent them showing up in GUILayout.TextFields? 2 Answers

Override Editor Controls 1 Answer


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