I have the following code:
tv.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
switch(keyCode)
{
case KeyEvent.KEYCODE_0:
Log.v(TAG, "Keycode_0");
return true;
//break;
case KeyEvent.KEYCODE_1:
Log.v(TAG, "Keycode_1");
return true;
//break;
case KeyEvent.KEYCODE_D:
Log.v(TAG, "Keycode_D");
return true;
//break;
case KeyEvent.KEYCODE_2:
Log.v(TAG, "Keycode_2");
return true;
//break;
case KeyEvent.KEYCODE_TAB:
Log.v(TAG, "Keycode_TAB");
return true;
//break;
case KeyEvent.KEYCODE_DEL:
Log.v(TAG, "Keycode_DEL");
return true;
//break;
case KeyEvent.KEYCODE_COMMA:
Log.v(TAG, "Keycode_COMMA");
return true;
//break;
case KeyEvent.KEYCODE_ENTER:
Log.v(TAG, "KEYCODE_ENTER");
i=KeyEvent.KEYCODE_ENTER;
Log.v(TAG, "KEYCODE_ENTER"+i);
return true;
//break;
case KeyEvent.KEYCODE_SHIFT_LEFT:
Log.v(TAG, "KEYCODE_SHIFT_LEFT"+KeyEvent.KEYCODE_SHIFT_LEFT);
return true;
//break;
case KeyEvent.KEYCODE_SHIFT_RIGHT:
Log.v(TAG, "KEYCODE_SHIFT_RIGHT"+KeyEvent.KEYCODE_SHIFT_RIGHT);
return true;
//break;
case KeyEvent.KEYCODE_SPACE:
Log.v(TAG, "KEYCODE_SPACE"+KeyEvent.KEYCODE_SPACE);
return true;
//break;
default:
break;
}
return false;
}
});
but it is working only for enter
and delete
keys. For the rest of the keys, it is not working. I wanted it for shift
and caps lock
keys.
The Android Keystore system lets you store cryptographic keys in a container to make it more difficult to extract from the device. Once keys are in the keystore, they can be used for cryptographic operations with the key material remaining non-exportable.
Key codes are numeric values that correspond to physical keys on the keyboard but do not necessarily correspond to a particular character.
Uset this listener on your editText:
editText.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
return false;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With