The Android input method takes precedence over the view key.
An example is written for verification.
First, the input method
public class RemoteKeyboard extends InputMethodService { @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (processKey(event, 0 != event.getRepeatCount())) return true; return super.onKeyDown(keyCode, event); } @Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (processKey(event, true)) return true; return super.onKeyUp(keyCode, event); } private boolean processKey(KeyEvent event, boolean doIt) { Log.e("======= " ," ============ processKey"); return false;}}
Second, app view
final TextView et1 = (TextView)findViewById(R.id.editText1);et1.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { Log.e("====================","====OnKeyListener "); }
Run program Printing
===================================: ============= ProcessKey
==================================== OnKeyListener
===================================: ============= ProcessKey
==================================== OnKeyListener
The first time should be KeyDown, and the second time should be KeyUp, indicating that the Android input method takes precedence over the view
I tried to rewrite system/usr/keychars/Generic. kcm.
Change B
Key B {
Base: 'B' fallback DPAD_CENTER
}
In a non-editable box, log is as follows:
05:18:09-23. 093 118 118 E ===============================: ============= processKey
05:18:09-23. 094 118 118 E ===============================: ============= processKey
05:18:09-23. 163 118 E =================================: ============= processKey
05:18:09-23. 163 118 E =================================: ============= processKey
It indicates that B is not accept, and then DPAD_CENTER is called.
In an editable box, B is accept, and the log is as follows:
===================================: ============= ProcessKey
===================================: ============= ProcessKey
Fallback is not called.
If the change is as follows:
Key B {
Base: fallback DPAD_CENTER
}
Four lines of log are required in an editable box, indicating that fallback is called.