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

Getting KB focus off the GUI TextField...

Discussion in 'Immediate Mode GUI (IMGUI)' started by jeremyace, Nov 9, 2007.

  1. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    I looked around for this, and I mentioned it here: http://forum.unity3d.com/viewtopic.php?t=7618

    I thought I'd better start this on its own thread and ask properly.

    I have code which uses a TextField and a confirmation button to enter data.

    The thing is, players enter that right in the main gameplay window, and I need the wasd keys to control the game after confirmation without also printing "aaassddd" in the TextField as it does now.

    My solution was to turn the TextField into a Label after the data was entered, which is fine, but for the future I'd like to know how to properly switch focus off the GUI.

    I found the options for setting some focus behaviour, but not for specifically taking KB focus off the GUI. I might be missing something dumb... That usually seems to be the case. ;-)

    If someone could tell me the proper way to do this that would be great, and if there is no way, consider it a request!

    Thanks,
    -Jeremy
     
  2. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    hey man, this is totally untested, but how about calling this after you're done?
    Code (csharp):
    1. GUI.FocusControl("");
    Or, failing that, using
    Code (csharp):
    1. GUI.enabled = false;
    2. //annoying textfield here
    3. GUI.enabled = true;
    as the manual says re GUI.Enabled:

    Any good?
     
  3. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Hey Shaun, thanks. I missed this when they moved it to the GUI section. ;-)

    I will try the focus control trick, but I don't want to be disabling the GUI as I need other controls to respond at runtime. My fix was to just flip a label in it's place, which works fine.

    Wanted to make sure I wan't missing something. Thanks a lot Shaun. ;-)

    -Jeremy
     
  4. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    You'll just be disabling that control, not the whole GUI ;)

    Give it a go and see if it works out your problem. HTH