"Turn Off" GUI.TextField by keyboard, not by mouse click

In my application the user won’t have a mouse. He will fill a GUI.TextField. I need to turn off / disable the input on GUI.TextField as is done via mouse click, only by tightening a keyboard button. I don’t want the GUI.TextField disappears, only to be “turned off” via a keyboard.


Check for a keyboard event. For example:

    bool off = (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.Enter || Event.current.keyCode == KeyCode.Return));

Then, when drawing the TextField, set GUI.enabled before and after:

    GUI.enabled = !off;
    GUI.enabled = true;