I'm currently trying to implement a framework to capture every user interaction with the application. I have an Activity that can capture the user key events as the following:
@Override
public boolean dispatchKeyEvent(@NonNull KeyEvent kEvent) {
final int action = kEvent.getAction();
final int keyCode = kEvent.getKeyCode();
final char character = (char) kEvent.getUnicodeChar();
if (action == KeyEvent.ACTION_UP) {
Log.i(">>>>DEBUG", "KEY EVENT");
final long res = kEvent.getEventTime() - this.timestampLastKeyboardEvent;
switch (keyCode) {
case KeyEvent.KEYCODE_DEL:
// FIXME
this.capuccinoEventLogger.removeLastCharacter();
break;
case KeyEvent.KEYCODE_TAB:
case KeyEvent.KEYCODE_ENTER:
this.capuccinoEventLogger.markLastCapuccinoEventFinal();
break;
default:
// HACK: there is a strange behaviour when a special character is
// typed the current method is invoked twice, one for the normal
// key and the other for the shift + key code.
if (res != 0) {
CapuccinoKeyboardEvent ce = new CapuccinoKeyboardEvent(character);
this.capuccinoEventLogger.addNewCapuccinoEvent(ce);
}
break;
}
this.timestampLastKeyboardEvent = kEvent.getEventTime();
}
return super.dispatchKeyEvent(kEvent);
}
The problem is, every key is being detected except for the backspace, when I'm trying to capture events from an EditText
. Why this is happening?