@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) { KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_UP); simulateKey(keyEvent); return true; } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) { KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_DOWN); simulateKey(keyEvent); return true; } } return super.dispatchKeyEvent(event); } public void simulateKey(final KeyEvent keyCode) { new Thread() { @Override public void run() { try { InputMethodManager systemService = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); systemService.dispatchKeyEventFromInputMethod(getRootView(), keyCode); } catch (Exception e) { } } }.start(); }
android 拦截按键 改变按键
最新推荐文章于 2024-09-21 10:46:40 发布