为什么我在Android的某些情况下无法获得KeyEvent.ACTION_DOWN?

时间:2014-12-20 12:39:42

标签: android keyevent event-dispatch-thread

通常情况下,当我按下一个键时,我可以得到两个动作:ACTION_DOWN ACTION_UP,但今天我遇到了一种情况,当我在遥控器中按right direction时,我无法得到ACTION_DOWN中的操作dispatchKeyEvent(event),只需获取操作ACTION_UP

是否因为其他一些方法拦截了这个事件?


实际上,调度代码是HorizontalScrollView executeKeyEvent(KeyEvent event)方法中的源代码:

if (event.getAction() == KeyEvent.ACTION_DOWN) {
            switch (event.getKeyCode()) {
                case KeyEvent.KEYCODE_DPAD_LEFT:
                    if (!event.isAltPressed()) {
                        handled = arrowScroll(View.FOCUS_LEFT);
                    } else {
                        handled = fullScroll(View.FOCUS_LEFT);
                    }
                    break;
                case KeyEvent.KEYCODE_DPAD_RIGHT:
                    if (!event.isAltPressed()) {
                        handled = arrowScroll(View.FOCUS_RIGHT);
                    } else {
                        handled = fullScroll(View.FOCUS_RIGHT);
                    }
                    break;
                case KeyEvent.KEYCODE_SPACE:
                    pageScroll(event.isShiftPressed() ? View.FOCUS_LEFT : View.FOCUS_RIGHT);
                    break;
            }
        }

0 个答案:

没有答案