title: Capturing Enter key on Android's onKeyDown
body: <p>I'm making a remote app that requires a keyboard. I'm not using an EditText, I am forcing it to invoke pragmatically.</p>
  
  <p>In the activity, I have a semi intelligent <code>onKeyDown</code> code that translates the android keycode into the ascii code processable by my server and sends it:</p>
  
  <pre><code>@Override 
  public boolean onKeyDown(int keyCode, KeyEvent event) {
      int asciiKey = -1;
      if (keyCode &gt;= KeyEvent.KEYCODE_A &amp;&amp; keyCode &lt;= KeyEvent.KEYCODE_Z) {
          asciiKey = keyCode - KeyEvent.KEYCODE_A + 'A';
      } else if (keyCode==KeyEvent.KEYCODE_DEL) {
          asciiKey = 8;
      } else if (keyCode==KeyEvent.KEYCODE_ENTER) {
          asciiKey = 13;
      } else {
          asciiKey = event.getUnicodeChar(event.getMetaState());
      }
      out.println("k "+asciiKey);
      return super.onKeyDown(keyCode, event);
  }
  </code></pre>
  
  <p>But when I press the <kbd>Enter</kbd> key, it's not sending (I've tried the Jelly Bean Default and Hacker's Keyboard). Not even a "-1". The method isn't even being called. It works for most other keys (Numbers, Letters, Backspace, Some Symbols) so it's not the app itself.</p>
  
  <p>The code that invokes the keyboard and hides it later:</p>
  
  <pre><code>InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
  imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
  </code></pre>
  
  <p>Is there something I'm missing? Also, is there a better way to translate Android keycodes into Ascii keys (specifically replicatable by <code>java.awt.Robot</code>).</p>
  
  <p>Thanks for any help in advance.</p>