title: How to catch key event when soft keyboard is shown programmatically?
body: <p>I'm trying to write text in <code>Canvas</code>. As I need to show the soft keyboard to write text, I added an <code>EditText</code> to my Activity with 0 width. I also implemented a TextWatcher to get the text entered into the <code>EditText</code>. With this trick, I can show the soft keyboard whenever I like with this code : </p>
  
  <pre><code>InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
  imm.showSoftInput(myEditText, InputMethodManager.SHOW_IMPLICIT);
  </code></pre>
  
  <p>Like this I'm able to know what the user is writing and to write the text inside my <code>Canvas</code>.</p>
  
  <p>Now... this becomes tricky when the user would like to stop writing (or let say, anchor the text in the canvas definitely). What I thought is that he could press 'Enter'. So I tried to implement some way to catch the key events. Without any success so far. </p>
  
  <p>Here is my actual code. This method is called when I would like to start writing. 'edit' is an <code>EditText</code>. </p>
  
  <pre><code>public void handleUp(final Paint myPaint) {
                  edit.setFocusable(true);
                  edit.setFocusableInTouchMode(true);
                  edit.requestFocus();
                  edit.addTextChangedListener(new Watcher());
                  edit.setImeOptions(EditorInfo.IME_ACTION_GO);
                  edit.setOnEditorActionListener(new OnEditorActionListener() {
                      public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {
                          Log.d("MyApp", "key pressed");
                          Paint localPaint = new Paint();
                          mCanvas.drawText(edit.getText().toString(), mX, mY, localPaint);
                          return false;
                      }
                  });
                  edit.setOnKeyListener(new OnKeyListener() {
                      public boolean onKey(View v, int keyCode, KeyEvent event) {
  
                          Log.d("MyApp", "key pressed");
                          if (keyCode == KeyEvent.ACTION_DOWN) {
                              Paint localPaint = new Paint();
                              mCanvas.drawText(edit.getText().toString(), mX, mY, localPaint);
                              return true;
                          }
                          return false;
                      }
                  });
                  InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                  imm.showSoftInput(edit, InputMethodManager.SHOW_IMPLICIT);
  
              }
  </code></pre>
  
  <p>When I debug my app I never reach check points that I have put on my <code>Log()</code> and can't see any message in my Logs neither. I have seen many posts on StackOverFlow where this kind of implementation is used by I can't figure out why it fails here.</p>
  
  <p>Thank you</p>