The following code may show the keyboard programmatically. Just catch the KeyEvent as you are doing in your question code and place this code inside that function:
yourEditText.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
InputMethodManager keyboard = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
keyboard.showSoftInput(mUserNameEdit, 0);
}
},0);
I do not recommend using InputMethodManager.SHOW_FORCED because it can cause strange layout issues. I would rather use this snippet in that case:
InputMethodManager mgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);