You can set onKeyListener() to EditText and get a KeyCode this way. For instance:
editText.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { switch(keyCode) { case KeyEvent.KEYCODE_0:
And in your switch just process all the necessary key codes. A complete list can be found in KeyEvent constants.
EDIT: Keep in mind for verification and the like, TextWatcher, as mentioned by Nicholas, may be the preferred solution if you need to know that the CHARACTER has been entered (for example, “A” versus “a”, how you will have to process the logic of whether the shift key is active or not in the key listener). If you just need to know which key was pressed, I would recommend OnKeyListener.
source share