Search Unity

Get current GUI control with focus?

Discussion in 'Immediate Mode GUI (IMGUI)' started by chrischris, Jan 3, 2008.

  1. chrischris

    chrischris

    Joined:
    Oct 18, 2005
    Posts:
    19
    How do I get the name of the GUI control that currently has focus?

    I've searched the forums docs but have found no way of doing so.

    Am I missing something obvious ( hopefully )?
     
  2. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    GUIUtility.keyboardControl -Use this to figure out which control has the caret/keyboard focus (I'm not confident this works 100% on windows though)
    GUIUtility.hotControl - use this to see which control is "active" i.e. has mousedown. It gets reset to 0 on mouseup.

    Also - there's a GUI section in this forum. Please post GUI questions there.

    Cheers
    Shaun
     
  3. chrischris

    chrischris

    Joined:
    Oct 18, 2005
    Posts:
    19
    GUIUtility.keyboardControl returns an integer that appears to be an internal ID. I can't find a straightforward way of getting this internal ID for a control. I would like to get the name of the control, since it is the only means we have to assign an ID.
     
  4. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    GUI.SetNextControlName and FocusControl are the only ways I know of accessing controls by name.
    I haven't tried this, but GUIUtility.GetControlID seems like it gets the ID of the next GUI control. Good luck :)
     
  5. ahmedvu153

    ahmedvu153

    Joined:
    Jan 26, 2015
    Posts:
    1
    I've searched the forums docs but have found no way of doing so