I'm trying to write text in `Canvas`. As I need to show the soft keyboard to write text, I added an `EditText` to my Activity with 0 width. I also implemented a TextWatcher to get the text entered into the `EditText`. With this trick, I can show the soft keyboard whenever I like with this code : 

```
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(myEditText, InputMethodManager.SHOW_IMPLICIT);

```

Like this I'm able to know what the user is writing and to write the text inside my `Canvas`.

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. 

Here is my actual code. This method is called when I would like to start writing. 'edit' is an `EditText`. 

```
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);

            }

```

When I debug my app I never reach check points that I have put on my `Log()` 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.

Thank you
['https://Stackoverflow.com/questions/15773588', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1685143/']
Taken from the documentation:

```
public void setOnKeyListener (View.OnKeyListener l)
Added in API level 1
Register a callback to be invoked when a hardware key is pressed in this view. Key presses    in software input methods will generally not trigger the methods of this listener.

```

So you should look for another listener.

My best guess would be to use this:

```
public void setOnEditorActionListener (TextView.OnEditorActionListener l)
Added in API level 3
Set a special listener to be called when an action is performed on the text view. This   will be called when the enter key is pressed, or when an action supplied to the IME is selected by the user. Setting this means that the normal hard key event will not insert a newline into the text view, even if it is multi-line; holding down the ALT modifier will, however, allow the user to insert a newline character.

```

But none of the methods I could see in the documentation mentioned anything about soft key input.
Okay so finally the reason nothing worked was because my `EditText` had a width of 0. When I put width and height to 1. Setting visibility to `View.INVISIBLE` doesn't work in this case. 

By the way, the three Listener (OnEditorActionListener, OnKeyListener and Overriding dispatchKeyEvent) get the callbacks. But I'll use `OnEditorActionListener` because it's the only one getting only one callback. The two others get several callbacks which is problematic.