title: Unity UI InputField detect enter or esc key when OnEndEdit
body: <p>I'm trying to figure out how to detect the end of editing an InputField with either the 'enter' or the 'esc' key. I have a working solution, but was wondering if there's a better way of doing it (using already existing Unity stuff). Actually using Unity 4.7.1</p>
  
  <p>Hereby is the actual solution:</p>
  
  <pre><code>using UnityEngine;
  using UnityEngine.UI;
  using UnityEngine.EventSystems;
  
  public class CustomInputField : InputField, ICancelHandler 
  {
      // Action others can subsribe
      public System.Action&lt;InputField, bool /*true: enter key, false: cancel key*/&gt; OnCustomEndEdit = null;
  
      override public void OnPointerClick (PointerEventData eventData) {
          base.OnPointerClick( eventData );
          if( eventData.clickCount &gt; 2 ) {
              SelectAll();
          }
      }
  
  
      // Need to presss 'enter' twice in order to receive this event. NOT USING IT!
      override public void OnSubmit(BaseEventData eventData) {
          base.OnSubmit( eventData );
      }
  
      // Need to presss 'esc' twice in order to receive this event. NOT USING IT!
      public void OnCancel(BaseEventData eventData) {
      }
  
  
      // This event happens before Unity calls the Update() funcion
      public void OnEndEdit( string value ) {
          if( Input.GetKeyDown( KeyCode.KeypadEnter ) || Input.GetKeyDown( KeyCode.Return ) ) {
              if( OnCustomEndEdit != null ) {
                  OnCustomEndEdit( this, true );
              }
              Debug.Log( "Enter Key: " + this.text );
          }
          else {
              if( Input.GetKeyDown( KeyCode.Escape ) ) {
                  if( OnCustomEndEdit != null ) {
                      OnCustomEndEdit( this, false );
                  }
                  Debug.Log( "Esc Key" );
              }
          }
      }        
  }
  </code></pre>