Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by TMPxyz · Oct 17, 2015 at 11:29 AM · c#guieditor-scriptingeditorgui

How to tell if any textField has keyboard focus in editor?

Hi,

I want to do shortcut keys in my editor, and I don't want it be triggered when we do typing in some TextField.

Although there's EditorGUIUtility.editingTextField, but this flag stays true even when you clicked outside the TextField, so this gives a unsatisfying result.

Thanks in advance,

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 TMPxyz · Oct 17, 2015 at 11:53 AM 0
Share

Hmm, though I cannot find out the most appropriate method to check the focus state, I do find a temporary workaround:

Just put this snippet at the start part in the OnGUI() method

 if (e.type == EventType.$$anonymous$$ouseDown && EditorWindow.focusedWindow == this)
             EditorGUIUtility.editingTextField = false;

then I could do the focus check with EditorGUIUtility.editingTextField again.

avatar image awesomedata TMPxyz · Apr 18, 2018 at 06:52 PM 0
Share

@T$$anonymous$$Pxyz See my answer below -- this does work as expected without the need for a big "if" statement. This handles input correctly as long as you put it in, say, an OnGUI event inside an editor window.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by awesomedata · Apr 18, 2018 at 06:50 PM

How are you checking the Debug.Log() and are you doing this in the Editor itself (i.e. EditorWindow)? -- If you are doing this in, say, an OnGUI event or in a custom Update method via delegate, then many times, the Debug.Log() does not change without mouse movement, and even as such, this depends on where you check and what else is taking up mouse input and then calling Use() on it. This could explain why the Debug.Log() is not updating.

That being said, the function EditorGUIUtility.editingTextField should only be called in the OnGUI event anyhow, and if all that is done correctly, it does handle input fields such as the searchbox in the project window (and other edit fields) correctly.

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
avatar image
1

Answer by praschl · Oct 31, 2021 at 01:23 PM

Ok this may be a bit old, but here the reason, EditorGUIUtility.editingTextField stays TRUE could be, that just clicking outside of a textfield doesn't necessarily make the focus of the textfield go away, it can stay focused. RETURN will remove the focus from the textbox. ESC will remove the focus from the textbox with undoing the edit. TAB will sometimes also remove the focus, depending on whats the next focusable ui element.

On the other hand, if you have the issue of EditorGUIUtility.editingTextField staying FALSE, even when the textbox is focused, try using EditorGUILayout.TextField instead of GUILayout.TextField, that solved my issue.

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

41 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Initialising List array for use in a custom Editor 1 Answer

Inspector removing MeshRenderer generates error 2 Answers

Default toggle style 1 Answer

How do I add something to the OnClick of a UI Button from an Editor-Script? 0 Answers

Custom Editor GUI Elements 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