I was trying to detect which key was pressed, so far I was able to detect SHIFT,BACKSPACE and ENTER with dispatchKeyEvent()
method but it seems that it won't detect the letters and numbers. And iv'e also tried the onKeyDown
and onKeyUp
and they don't even detect the SHIFT,BACKSPACE and ENTER let alone the alphabet and letters.
My goal is to type a letter in my EditText
and detect the KeyStroke and display it with Toast
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int keyaction = event.getAction();
if(keyaction == KeyEvent.ACTION_DOWN )
{
String keycode = event.getCharacters();
Toast toast = Toast.makeText(this,String.valueOf(event.getKeyCode()), Toast.LENGTH_LONG);
toast.show();
}
return super.dispatchKeyEvent(event);
}
This is detecting the Keycode for SHIFT,BACKSPACE and ENTER but not the alphabets
use something like this :