1

For some reason, onKeyUp always follows onKeyDown for every ascii key on hardware bluetooth keyboard.

If you press DPAD_UP, no problem.

If you let the key pressed, OnKeyDown is called several times with repeatCount increasing.

OnKeyUp is fired only when you release the key.

Using Log.d("KEY", "down " + event.getDisplayLabel() + " " + event.getRepeatCount());

   ...
   2019-11-29 23:42:20.036 14217-14217/com.test D/KEY: down �� 13
   2019-11-29 23:42:20.086 14217-14217/com.test D/KEY: down �� 14
   2019-11-29 23:42:20.141 14217-14217/com.test D/KEY: down �� 15
   2019-11-29 23:42:20.191 14217-14217/com.test D/KEY: down �� 16

If you press A, OnKeyDown is fired and OnKeyUp almost immediately after (with downTime = eventime) If you let the key pressed, OnKeyUp follow every OnKeyDown, repeatCount stays at 0.

Using Log.d("KEY", "down " + event.getDisplayLabel() + " " + event.getRepeatCount());

2019-11-29 23:42:20.976 14217-14217/com.test D/KEY: down A 0
2019-11-29 23:42:25.002 14217-14217/com.test D/KEY: down A 0
2019-11-29 23:45:04.533 14217-14217/com.test D/KEY: down A 0

OnKeyDown/OnKeyUp are defined on my surfaceView, added to an AppCompatActivity with

view.setFocusable(true);
view.setFocusableInTouchMode(true);

appcompat-v7:28.0.0 (same behavior confirmed on every version since 26.1.0)

targetSDK 29

minSDK 14



Very similar issues but without answer unfortunately

KeyEvent getRepeatCount() always return 0

Android: how to detect keyboard press and release events?

KanedaFr
  • 76
  • 6

0 Answers0