(Please read below and don’t just suggest Event.current.keyCode. Thanks!)
If a Unity GUI button has keyboard focus and the player presses KeyCode.Space, it clicks the button. For example, if you add this to a scene and press Space, it will log “CLICKED!”.
public void OnGUI() {
GUI.SetNextControlName("ClickMeControlName");
if (GUILayout.Button("Click Me")) Debug.Log ("CLICKED!");
GUI.FocusControl("ClickMeControlName");
}
Is it possible to change Unity GUI’s default behavior to a different KeyCode, such as KeyCode.Return? I’d prefer this to watching Event.current.keyCode for Space (to Use it to prevent it from clicking the button) and Return to simulate a click.