作者:一粒星尘ch | 来源:互联网 | 2023-08-07 18:02
5 transfer the inputtext into app
Keyevent
- InputConnection ic = getCurrentInputConnection();
- long eventTime = SystemClock.uptimeMillis();
- ic.sendKeyEvent(new KeyEvent(eventTime, eventTime,
- KeyEvent.ACTION_DOWN, keyEventCode, 0, 0, 0, 0,
- KeyEvent.FLAG_SOFT_KEYBOARD|KeyEvent.FLAG_KEEP_TOUCH_MODE));
- ic.sendKeyEvent(new KeyEvent(SystemClock.uptimeMillis(), eventTime,
- KeyEvent.ACTION_UP, keyEventCode, 0, 0, 0, 0,
- KeyEvent.FLAG_SOFT_KEYBOARD|KeyEvent.FLAG_KEEP_TOUCH_MODE));
InputMethodService.sendDownUpKeyEvents(keyEventCode);
input by lenovo
- InputConnection ic = getCurrentInputConnection();
- ic.setComposingText("Composi", 1);
6 deal with the hard keybard event
if you want to deal with the hard key event ,you can overide the InputMethodService.onKeyDown() and InputMethodService.onKeyUp();if not ,just use the super.onKey*.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (event.getRepeatCount() == 0 && mInputView != null) {
if (mInputView.handleBack()) {
return true;
}
}
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
case KeyEvent.KEYCODE_DPAD_UP:
case KeyEvent.KEYCODE_DPAD_LEFT:
case KeyEvent.KEYCODE_DPAD_RIGHT:
break;
}
if( bIsRussianHardboard == true && (System.currentTimeMillis() - iLastPressTime {
bIsReplaced = true;
Log.i("isReplace", bIsReplaced + ";" );
iLastPressTime = -1;
final InputConnection ic = getCurrentInputConnection();
CharSequence lastChar = ic.getTextBeforeCursor(2, 0);
if (lastChar != null && lastChar.length() == 1
&& (lastChar.charAt(0)== '/u0419'||lastChar.charAt(0)== '/u042F'||lastChar.charAt(0)== '/u0416'||lastChar.charAt(0)== '/u0425'||lastChar.charAt(0)== '/u041B'||lastChar.charAt(0) ==KEYCODE_PERIOD))
{
Log.i("LASTCHAR", lastChar.charAt(0)+ ";");
hardCap = true;
}
else
{
hardCap = false;
}
handleBackspace();
}
else
{
bIsReplaced = false;
iLastKeycode = keyCode;
iLastPressTime = System.currentTimeMillis();
}
// sym is used to make the change of russian and english in russiankeyboard mode
if (event.isSymPressed())
{
changeKeyboardLanguage();
mHardKeyboard.updateMetaStateAfterKeypress(HardKeyboardState.META_SHIFT, true);
return true;
}
// Do translation into Russian if necessary
if (KeyboardSwitcher.LANGUAGE_RU == mKeyboardSwitcher.getKeyboardLanguage()
&& handleHardKeyRussian(keyCode, event)) {
bIsRussianHardboard = true;
return true;
} else {
return super.onKeyDown(keyCode, event);
}
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_DOWN:
case KeyEvent.KEYCODE_DPAD_UP:
case KeyEvent.KEYCODE_DPAD_LEFT:
case KeyEvent.KEYCODE_DPAD_RIGHT:
// Enable shift key and DPAD to do selections
if (mInputView != null && mInputView.isShown() && mInputView.isShifted()) {
event = new KeyEvent(event.getDownTime(), event.getEventTime(),
event.getAction(), event.getKeyCode(), event.getRepeatCount(),
event.getDeviceId(), event.getScanCode(),
KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_ON);
InputConnection ic = getCurrentInputConnection();
if (ic != null) ic.sendKeyEvent(event);
return true;
}
break;
}
return super.onKeyUp(keyCode, event);
}