Edit: This does seem to be specific to TextMeshPro’s input field. After originally posting and further research, this is relevant to the issue: TextMeshPro onSubmit() being called with escape key
Original post:
Apologies in advance if this has been addressed before, I searched and couldn’t find anything directly relevant.
The observed behavior (symptom): I have a textmesh pro input field, and when it is selected in playmode, pressing the Escape key on the keyboard causes the text to be submitted, just like hitting the Enter key does. To be more specific, I have it wired up as:
[SerializeField] private TMP_InputField inputField;
...
inputField.onSubmit.AddListener(OnSubmitInput);
...
… where when I press escape, the OnSubmitInput method I have defined is being called.
My question: WHY?
I have been trying to wrap my head around this behavior, of why Escape would be triggering a ‘submit’. The action map being used is the default ‘UI’ action map from the input action asset. In that action map, the “Submit” Action has the binding ‘Submit [any]’.
The manual (UI support | Input System | 1.0.2) states under the ‘Navigation-type input’ section: “…input from submit will trigger ISubmitHandler on the currently selected object and Cancel will trigger ICancelHandler on it.”
And (UI support | Input System | 1.0.2) under the ‘submit’ entry in the table says “An Action to engage with or “click” the currently selected UI selectable. See navigation-type input.”
…which taken at face value, makes sense. What doesn’t make sense to me, though is why the ESCAPE key of all things would be triggering the ‘submit’. This is about as intuitive (to me) as “press cancel to confirm” or the brake increasing speed of the car, or the “off” button turning a device on. Maybe my expectation for what the escape key should do is flawed. I would expect it to trigger a behavior like ‘cancel’ or ‘back’ or something along those lines.
I don’t know how to look further under the hood to see how the ‘submit [any]’ binding is being wired up for ‘escape’, so if anyone has any suggestion about how to explore (and change) this, it would be appreciated.
I don’t want to have to manually re-bind this in the action map, because I appreciate the benefits of the abstraction. I just am having trouble comprehending the observed behavior.
Thanks in advance for any insight into understanding why this is like this, and/or how to change it.
Edit: Followup question: If Escape triggers ‘Submit [Any]’ what will trigger ‘Cancel [Any]’ ?