For example, send a backspace key to the edit text control to remove a character or send a char code like 112 to append a character in the edittext control programmatically.
Actually, I need a method like
void onKeyReceived(int keyCode)
{
// here I would like to append the keyCode to EditText, I know how to add a visible character, but what about some special keys, like arrow key, backspace key.
}
virsir , I suppose you are looking for dispatching hard keys programmatically.
For that you may try dispatch (KeyEvent.Callback receiver, KeyEvent.DispatcherState state, Object target) with an example at Back and other hard keys: three stories
Hope that helps.
Take a look at this article: creating-input-method.html. Basically, you can either manually send
KeyEvents
or you can manuallyedit and commit text around the cursor
in the application'sInput View
.These are all done via your IME'sInputConnection
.Hope this helps,
Check for key events in your activity. for example, this code listens for
back
keypress:try implementing TextWatcher interface.
it has 3 methods which you need to override.
I think this will work.