I tried to send keyevent from EditText . For this, I used InputConnectionWrapper , which I took from the onCreateInputConnection() method:
ZanyInputConnection zic; @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { zic = new ZanyInputConnection(super.onCreateInputConnection(outAttrs), true); return zic; }
Inside ZanyInputConnection I wrote a method that involves a shift:
private class ZanyInputConnection extends InputConnectionWrapper { public ZanyInputConnection(InputConnection target, boolean mutable) { super(target, mutable); } public void turnOnShift(){ long eventTime = SystemClock.uptimeMillis(); sendKeyEvent(new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_SOFT_KEYBOARD|KeyEvent.FLAG_KEEP_TOUCH_MODE)); sendKeyEvent(new KeyEvent(eventTime, SystemClock.uptimeMillis(), KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_SOFT_KEYBOARD|KeyEvent.FLAG_KEEP_TOUCH_MODE)); } }
It is called inside the onSelectionChange() method:
@Override public void onSelectionChanged(int selStart, int selEnd) { zic.turnOnShoft(); }
But when a method called nothing happens.
EDIT:
If I use KeyEvent.KEYCODE_A later than 'a' add, but if I use KeyEvent.KEYCODE_SHIFT_LEFT, it does not work