KeyEvent getRepeatCount() always return 0
Asked Answered
N

1

5

I'm working with remote android TV To catch event when use press remote button I use this code:

public boolean dispatchKeyEvent(KeyEvent event) {
        Log.d("LOG", "Number repeate count = " + event.getRepeatCount());
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            switch (event.getKeyCode()) {
                case KeyEvent.KEYCODE_1:
                    exoPlayerManager.showControllerView();
                    if (event.getRepeatCount() > 0) {
                        if (videoPlayerView.getPlaybackControlView().getPlayer().getPlaybackParameters().speed >= 64) {
                            ((TextView)videoPlayerView.getPlaybackControlView().findViewById(R.id.exo_rate)).setVisibility(View.GONE);
                            videoPlayerView.getPlaybackControlView().getPlayer().setPlaybackParameters(new PlaybackParameters(1, 1.0f));
                        } else {
                            videoPlayerView.getPlaybackControlView().getPlayer().setPlaybackParameters(new PlaybackParameters(2 * videoPlayerView.getPlaybackControlView().getPlayer().getPlaybackParameters().speed, 1.0f));
                        }
                        ((TextView)videoPlayerView.getPlaybackControlView().findViewById(R.id.exo_rate)).setText(videoPlayerView.getPlaybackControlView().getPlayer().getPlaybackParameters().speed + "X");
                    }else  if (videoPlayerView.getPlaybackControlView() != null) {
                        return videoPlayerView.getPlaybackControlView().dispatchKeyEvent(event);
                    }
                    break;

I see that when I press 1 button on remote, getRepeateCount() always return 0. I think if i pressed duplicate it should be greater 0.

What is wrong here ?

Nocti answered 15/12, 2017 at 2:49 Comment(0)
T
8

When you press a key, release it, and then press it again, you will receive two ACTION_DOWN events, and getRepeatCount() will return 0 for both. To see a non-zero getRepeatCount() value, you have to hold down the key long enough that it starts repeating.

You can think about it like this. If I type "aaaaaaaaaa" into this text field by pressing and releasing my keyboard's A key 10 times, I'll get 10 events, each with a repeat count of zero. But if I hold my A key down long enough that I start getting multiple "a"s, then I'll get 10 events, each with an increasing repeat count.

Towers answered 15/12, 2017 at 3:12 Comment(2)
Hi @Ben P, I press number 1 many time, long click, double click, long press , ... but getRepeatCount() still 0Nocti
@phongvan This behavior is not intended for all keys, try pressing back button to see itEllord

© 2022 - 2024 — McMap. All rights reserved.