Access to GUI Keyboard Focus

Hey guys,

So I asked a pretty in depth question yesterday, which you can view [here][1]. Haven’t gotten any hits as of yet, so I thought I’d simplify the question to something I can work with for now.

Question Is there a way to gain script access to which button has keyboard focus?

I can apply a GUI skin to a button that has the functionality of changing text color and background texture while a button has keyboard focus, but I’d like to be able to animate/scale a button while it’s focused, not when it’s pushed. Anyone know of a way to do this?

EDIT: Didn’t think to provide code so you all can see how I do this -.-
Like I said to David, I utilize a string array in which I add menu items in the inspector, after which I have a “for” loop that creates a button for every array item. Here’s the code:

function OnGUI () {

    GUI.BeginGroup (Rect (0, Screen.height / 4, Screen.width / 2, Screen.height / 2));	// Begin group to nest the following  GUI elements in
    
    for (i = 0; i < menuOptions.Length; i++) {					// For every menu option we have...
		GUI.SetNextControlName (menuOptions*);				// Assign a control name*

_ GUI.Button (Rect (0, 0 + (((Screen.height / 18) * 1.25) * i), Screen.width / 2.5, Screen.height / 18), menuOptions*); // Create a scalable button*_
}
* GUI.EndGroup (); // End the group*
* GUI.FocusControl (menuOptions[selectedIndex]); // Set focus control to the selected menu option*
}
NOTE The “selectedIndex” variable within “GUI.FocusControl” is an integer that is determined based upon the up/down selection keys. For example - if selectedIndex = 0, the first button is highlighted, etc. Am I utilizing FocusControl & SetNextControl name properly?
Thanks!
Clopay
_*[1]: http://answers.unity3d.com/questions/373928/main-menu-gui-button-animation.html*_

You can use GUIUtility.keyboardControl to get the ID of the focussed element, then compare that against the control ID.

Example code in C# (Unityscript version is almost identical)

GUIContent content = new GUIContent("I'm a button!");
int controlId = GUIUtility.GetControlID(content, FocusType.Keyboard);
if (GUIUtility.keyboardControl == controlId) {
	Debug.Log("It's got focus - " + controlId);
}
	
if (GUI.Button(new Rect(10,10,100,30), content)) {
	Debug.Log("Clicked the control button");
}